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
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic doublegetFromRange(double start, double stop) getFromRange(double start, double stop, Optional<Long> seed, int numSamples) Randomly selects a value from the given range.static doublegetNormalVariate(double mean, double stddev) getNormalVariate(double mean, double stddev, Optional<Long> seed, int numSamples) Randomly selects a value from a normal distribution with the given mean and standard deviation.static Objectstatic Objectstatic ObjectPicks an item based on a weighted random choice.static ObjectPicks an item randomly from the given list.
-
Constructor Details
-
RandomUtils
public RandomUtils()
-
-
Method Details
-
getNormalVariate
public static List<Double> getNormalVariate(double mean, double stddev, Optional<Long> seed, int numSamples) 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.
-
getNormalVariate
public static double getNormalVariate(double mean, double stddev) -
getFromRange
public static List<Double> getFromRange(double start, double stop, Optional<Long> seed, int numSamples) Randomly selects a value from the given range. Assumes values are uniformly distributed. The range is from start (inclusive) to stop (exclusive).
-
getFromRange
public static double getFromRange(double start, double stop) -
pick
Picks an item based on a weighted random choice.
- Parameters:
items- the items to choose fromweights- the weighted probabilities
-
pick
-
pick
Picks an item randomly from the given list.
-
pick
-