Class RandomNumbersTool

  • All Implemented Interfaces:
    Serializable

    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:
    Serialized Form
    Source code:
    main
    Belongs to CDK module:
    standard
    • Constructor Detail

      • RandomNumbersTool

        public RandomNumbersTool()
    • Method Detail

      • 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.