Package nz.org.riskscape.engine.util
Class RandomUtils
java.lang.Object
nz.org.riskscape.engine.util.RandomUtils
Helper functions for generating random numbers or sampling from random distributions.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic double
getFromRange
(double start, double stop) Randomly selects a value from the given range.static double
getNormalVariate
(double mean, double stddev) Randomly selects a value from a normal distribution with the given mean and standard deviation.static Object
Picks an item randomly from the given list.static Object
Picks an item based on a weighted random choice.
-
Constructor Details
-
RandomUtils
public RandomUtils()
-
-
Method Details
-
getNormalVariate
public static double getNormalVariate(double mean, double stddev) Randomly selects a value from a normal distribution with the given mean and standard deviation. This means that values closer to the mean have a higher likelihood of being selected.
-
getFromRange
public static double getFromRange(double start, double stop) Randomly selects a value from the given range. Assumes values are uniformly distributed. The range is from start (inclusive) to stop (exclusive).
-
pick
Picks an item based on a weighted random choice.
- Parameters:
items
- the items to choose fromweights
- the weighted probabilities
-
pick
Picks an item randomly from the given list.
-