weighted_random v0.1.0 WeightedRandom View Source
Link to this section Summary
Functions
Examples
Takes a different weight for each value, and randomly returns a value. If each map has the same weight, they will all be equally likely to be returned. A map with a relatively higher weight will be more likely to be returned. ## Examples
Examples
Gets a random number between min and max. If the weight is 1, then it’s purely random. If the weight is higher, then the number will be closer to the target
Link to this section Functions
## Examples
iex> WeightedRandom.between(0, 100) 23
Takes a different weight for each value, and randomly returns a value. If each map has the same weight, they will all be equally likely to be returned. A map with a relatively higher weight will be more likely to be returned. ## Examples
iex> maplist = [ %{:value => :red, :weight => 15}, %{:value => :blue, :weight => 1}, %{:value => :yellow, :weight => 5} ] iex> WeightedRandom.complex(maplist) :red
## Examples
iex> WeightedRandom.numList(0, 100, 10) [87, 19, 8, 20, 11, 37, 85, 88, 69, 47, 39]
Gets a random number between min and max. If the weight is 1, then it’s purely random. If the weight is higher, then the number will be closer to the target
## Examples
iex> WeightedRandom.weighted(0, 100, 75, 10) 83