Class RandomUtil

java.lang.Object
edu.cmu.tetrad.util.RandomUtil

public class RandomUtil extends Object
Provides a common random number generator to be used throughout Tetrad, to avoid problems that happen when random number generators are created more often than once per millisecond. When this happens, the generators are synced, and there is less randomness than expected.

A seed can be set for the generator using the setSeed method. This is useful if an experiment needs to be repeated under different conditions. The seed for an experiment can be printed using the getSeed method.

The 64-bit Mersenne Twister implementation from the COLT library is used to generate random numbers.

To see what distributions are currently supported, look at the methods of the class. These many change over time.

Author:
josephramsey
  • Method Details

    • getInstance

      public static RandomUtil getInstance()
      Returns:
      the singleton instance of this class.
    • shuffle

      public static void shuffle(List<?> list)
      This is just the RandomUtil.shuffle method (thanks!) but using the Tetrad RandomUtil to get random numbers. The purpose of this copying is to allow shuffles to happen deterministically given the Randomutils seed.
      Parameters:
      list - The list to be shuffled.
    • main

      public static void main(String[] args)
    • nextInt

      public int nextInt(int n)
      Parameters:
      n - Ibid.
      Returns:
      Ibid.
    • nextDouble

      public double nextDouble()
    • nextUniform

      public double nextUniform(double low, double high)
      Parameters:
      low - Ibid.
      high - Ibid.
      Returns:
      Ibid.
    • nextNormal

      public double nextNormal(double mean, double sd)
      Parameters:
      mean - The mean of the Normal.
      sd - The standard deviation of the Normal.
      Returns:
      Ibid.
    • nextTruncatedNormal

      public double nextTruncatedNormal(double mean, double sd, double low, double high)
      Parameters:
      mean - The mean of the Normal.
      sd - The standard deviation of the Normal.
      Returns:
      Ibid.
    • revertSeed

      public void revertSeed(long seed)
    • nextPoisson

      public double nextPoisson(double lambda)
      Parameters:
      lambda - A positive real number equal to the expected number of occurrences during a given interval. See Wikipedia.
      Returns:
      Ibid.
    • normalPdf

      public double normalPdf(double mean, double sd, double value)
      Parameters:
      mean - The mean of the normal to be used.
      sd - The standard deviation of the normal to be used.
      value - The domain value for the PDF.
      Returns:
      Ibid.
    • normalCdf

      public double normalCdf(double mean, double sd, double value)
      Parameters:
      mean - The mean of the normal to be used.
      sd - The standard deviation of the normal to be used.
      value - The domain value for the CDF.
      Returns:
      Ibid.
    • nextBeta

      public double nextBeta(double alpha, double beta)
      Parameters:
      alpha - See Wikipedia. This is the first parameter.
      beta - See Wikipedia. This is the second parameter.
      Returns:
      Ibid.
    • nextT

      public double nextT(double df)
      Parameters:
      df - The degrees of freedom. See any stats book.
      Returns:
      Ibid.
    • nextExponential

      public double nextExponential(double lambda)
      Parameters:
      lambda - The rate parameter. See Wikipedia.
      Returns:
      Ibid.
    • nextGumbel

      public double nextGumbel(double mu, double beta)
      Returns:
      Ibid.
    • nextChiSquare

      public double nextChiSquare(double df)
      Parameters:
      df - The degrees of freedom.
      Returns:
      Ibid.
    • nextGamma

      public double nextGamma(double shape, double scale)
      Parameters:
      shape - The shape parameter.
      scale - The scale parameter.
      Returns:
      Ibid.
    • setSeed

      public void setSeed(long seed)
      Sets the seed to the given value.
      Parameters:
      seed - A long value. Once this seed is set, the behavior of the random number generator is deterministic, so setting the seed can be used to repeat previous behavior.
    • getRandomGenerator

      public org.apache.commons.math3.random.RandomGenerator getRandomGenerator()
    • nextLong

      public long nextLong()