Class RNGDistribution.Uniform

Enclosing class:
RNGDistribution

public static class RNGDistribution.Uniform extends RNGDistribution
Uniformly distributed random numbers with support [min, max).
See Also:
  • Field Details

    • min

      private double min
      Lower bound of uniform interval (inclusive).
    • range

      private double range
      Width of interval of uniform random numbers, max-min.
  • Constructor Details

    • Uniform

      public Uniform()
      Creates uniform random distribution in interval [0,1) with new instance of MersenneTwister.
    • Uniform

      public Uniform(double min, double max)
      Creates uniform random distribution in interval [min, max) with new instance of MersenneTwister.
      Parameters:
      min - lower bound of uniform interval (inclusive)
      max - upper bound of uniform interval (exclusive)
    • Uniform

      public Uniform(MersenneTwister rng, double min, double max) throws IllegalArgumentException
      Creates uniform random distribution in interval [min, max) with random number generator rng.
      Parameters:
      rng - random number generator
      min - lower bound of uniform interval (inclusive)
      max - upper bound of uniform interval (exclusive)
      Throws:
      IllegalArgumentException - if max≤min
      See Also:
  • Method Details

    • getMin

      public double getMin()
      Get the lower bound of the uniform distribution (inclusive).
      Returns:
      the lower bound
    • getMax

      public double getMax()
      Get the upper bound of the uniform distribution (exclusive).
      Returns:
      the upper bound
    • getRange

      public double getRange()
      Get the range of the uniform distribution.
      Returns:
      the range of the interval max-min
    • next

      public double next()
      Generate a uniformly distributed random number from interval [min, max).
      Returns:
      the uniformly distributed random number
    • clone

      public RNGDistribution.Uniform clone()
      Description copied from class: RNGDistribution
      Clone this RNGDistribution to ensure both objects return identical sequences of random numbers.

      IMPORTANT:

      1. overrides clone() in Object but conflicts with GWT's aversion to clone()ing...
      2. remove @SuppressWarnings("all") to ensure that no other issues crept in when modifying method.
      Specified by:
      clone in class RNGDistribution
      Returns:
      clone of RNGDistribution
    • next

      public static double next(MersenneTwister rng, double min, double max)
      Uniformly distributed random number in [min, max) using random number generator rng.

      Note: no performance difference between the instance method next() and this static counterpart.

      Parameters:
      rng - random number generator
      min - lower bound of uniform interval (inclusive)
      max - upper bound of uniform interval (exclusive)
      Returns:
      uniformly distributed random number from interval [min, max)
      Throws:
      IllegalArgumentException - if max≤min
    • test

      public static void test(MersenneTwister rng, Logger logger, MersenneTwister.Chronometer clock)
      Test Uniform distribution. The test samples the distribution and bins the random numbers. This sample distribution is compared to the theoretical expectation. The mean deviation is the mean difference between the actual number of events in each bin and their expected number. For a perfect match the mean deviation is 0. The test passes if the mean deviation lies within one standard error from 0. This is more stringent than the traditional 95% confidence interval.
      Parameters:
      rng - the random number generator
      logger - the logger for reporting results
      clock - the stop watch
      See Also:
    • cdf

      private static double cdf(double x, double min, double max)
      Helper method to calculate the cumulative distribution function, cdf, of the Uniform distribution.
      Parameters:
      x - the value for which to calculate the cdf
      min - the minimum value
      max - the maximum value
      Returns:
      cdf at x