Class RandomNumbersTool

java.lang.Object
java.util.Random
org.openscience.cdk.math.RandomNumbersTool
All Implemented Interfaces:
Serializable, java.util.random.RandomGenerator

public class RandomNumbersTool extends Random
Class supplying useful methods to generate random numbers. This class isn't supposed to be instantiated. You should use it by calling its static methods.
See Also:
Source code:
main
Belongs to CDK module:
standard
  • Nested Class Summary

    Nested classes/interfaces inherited from interface java.util.random.RandomGenerator

    java.util.random.RandomGenerator.ArbitrarilyJumpableGenerator, java.util.random.RandomGenerator.JumpableGenerator, java.util.random.RandomGenerator.LeapableGenerator, java.util.random.RandomGenerator.SplittableGenerator, java.util.random.RandomGenerator.StreamableGenerator
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static double
    exponentialDouble(double mean)
    Generates a random double from an Exponential distribution with the specified mean value.
    static boolean
    flipCoin(double p)
    Returns a boolean value based on a biased coin toss.
    static double
    gaussianDouble(double dev)
    Generates a random double from a Gaussian distribution with the specified deviation.
    static float
    gaussianFloat(float dev)
    Generates a random float from a Gaussian distribution with the specified deviation.
    static Random
    Returns the instance of Random used by this class.
    static long
    Returns the seed being used by this random number generator.
    static int
    Generates a random bit: either 0 or 1.
    static boolean
    Generates a random boolean.
    static double
    Generates a random double between 0 and 1.
    static double
    randomDouble(double lo, double hi)
    Generates a random double between the specified values.
    static float
    Generates a random float between 0 and 1.
    static float
    randomFloat(float lo, float hi)
    Generates a random float between the specified values.
    static int
    Generates a random integer between 0 and 1.
    static int
    randomInt(int lo, int hi)
    Generates a random integer between the specified values.
    static long
    Generates a random long between 0 and 1.
    static long
    randomLong(long lo, long hi)
    Generates a random long between the specified values.
    static void
    setRandom(Random base_random)
    Sets the base generator to be used by this class.
    static void
    setRandomSeed(long new_seed)
    Sets the seed of this random number generator using a single long seed.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface java.util.random.RandomGenerator

    isDeprecated, nextDouble, nextDouble, nextExponential, nextFloat, nextFloat, nextGaussian, nextInt, nextLong, nextLong
  • Constructor Details

    • RandomNumbersTool

      public RandomNumbersTool()
  • Method Details

    • setRandom

      public static void setRandom(Random base_random)
      Sets the base generator to be used by this class.
      Parameters:
      base_random - a java.util.Random subclass.
    • setRandomSeed

      public static void setRandomSeed(long new_seed)
      Sets the seed of this random number generator using a single long seed.
      Parameters:
      new_seed - the seed to be used by the random number generator.
    • getRandomSeed

      public static long getRandomSeed()
      Returns the seed being used by this random number generator.
      Returns:
      the long seed.
    • getRandom

      public static Random getRandom()
      Returns the instance of Random used by this class.
      Returns:
      An object of Random
    • randomInt

      public static int randomInt()
      Generates a random integer between 0 and 1.
      Returns:
      a random integer between 0 and 1.
    • randomInt

      public static int randomInt(int lo, int hi)
      Generates a random integer between the specified values.
      Parameters:
      lo - the lower bound for the generated integer.
      hi - the upper bound for the generated integer.
      Returns:
      a random integer between lo and hi.
    • randomLong

      public static long randomLong()
      Generates a random long between 0 and 1.
      Returns:
      a random long between 0 and 1.
    • randomLong

      public static long randomLong(long lo, long hi)
      Generates a random long between the specified values.
      Parameters:
      lo - the lower bound for the generated long.
      hi - the upper bound for the generated long.
      Returns:
      a random long between lo and hi.
    • randomFloat

      public static float randomFloat()
      Generates a random float between 0 and 1.
      Returns:
      a random float between 0 and 1.
    • randomFloat

      public static float randomFloat(float lo, float hi)
      Generates a random float between the specified values.
      Parameters:
      lo - the lower bound for the generated float.
      hi - the upper bound for the generated float.
      Returns:
      a random float between lo and hi.
    • randomDouble

      public static double randomDouble()
      Generates a random double between 0 and 1.
      Returns:
      a random double between 0 and 1.
    • randomDouble

      public static double randomDouble(double lo, double hi)
      Generates a random double between the specified values.
      Parameters:
      lo - the lower bound for the generated double.
      hi - the upper bound for the generated double.
      Returns:
      a random double between lo and hi.
    • randomBoolean

      public static boolean randomBoolean()
      Generates a random boolean.
      Returns:
      a random boolean.
    • randomBit

      public static int randomBit()
      Generates a random bit: either 0 or 1.
      Returns:
      a random bit.
    • flipCoin

      public static boolean flipCoin(double p)
      Returns a boolean value based on a biased coin toss.
      Parameters:
      p - the probability of success.
      Returns:
      true if a success was found; false otherwise.
    • gaussianFloat

      public static float gaussianFloat(float dev)
      Generates a random float from a Gaussian distribution with the specified deviation.
      Parameters:
      dev - the desired deviation.
      Returns:
      a random float from a Gaussian distribution with deviation dev.
    • gaussianDouble

      public static double gaussianDouble(double dev)
      Generates a random double from a Gaussian distribution with the specified deviation.
      Parameters:
      dev - the desired deviation.
      Returns:
      a random double from a Gaussian distribution with deviation dev.
    • exponentialDouble

      public static double exponentialDouble(double mean)
      Generates a random double from an Exponential distribution with the specified mean value.
      Parameters:
      mean - the desired mean value.
      Returns:
      a random double from an Exponential distribution with mean value mean.