Class RandomUtils

java.lang.Object
nz.org.riskscape.engine.util.RandomUtils

public class RandomUtils extends Object

Helper functions for generating random numbers or sampling from random distributions.

  • 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

      public static Object pick(List<?> items, List<Double> weights)

      Picks an item based on a weighted random choice.

      Parameters:
      items - the items to choose from
      weights - the weighted probabilities
    • pick

      public static Object pick(List<?> items)

      Picks an item randomly from the given list.