Package org.openscience.cdk.math
Class RandomNumbersTool
java.lang.Object
java.util.Random
org.openscience.cdk.math.RandomNumbersTool
- All Implemented Interfaces:
Serializable,RandomGenerator
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:
-
Nested Class Summary
Nested classes/interfaces inherited from interface java.util.random.RandomGenerator
RandomGenerator.ArbitrarilyJumpableGenerator, RandomGenerator.JumpableGenerator, RandomGenerator.LeapableGenerator, RandomGenerator.SplittableGenerator, RandomGenerator.StreamableGenerator -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic doubleexponentialDouble(double mean) Generates a random double from an Exponential distribution with the specified mean value.static booleanflipCoin(double p) Returns a boolean value based on a biased coin toss.static doublegaussianDouble(double dev) Generates a random double from a Gaussian distribution with the specified deviation.static floatgaussianFloat(float dev) Generates a random float from a Gaussian distribution with the specified deviation.static RandomReturns the instance of Random used by this class.static longReturns the seed being used by this random number generator.static intGenerates a random bit: either0or1.static booleanGenerates a random boolean.static doubleGenerates a random double between0and1.static doublerandomDouble(double lo, double hi) Generates a random double between the specified values.static floatGenerates a random float between0and1.static floatrandomFloat(float lo, float hi) Generates a random float between the specified values.static intGenerates a random integer between0and1.static intrandomInt(int lo, int hi) Generates a random integer between the specified values.static longGenerates a random long between0and1.static longrandomLong(long lo, long hi) Generates a random long between the specified values.static voidSets the base generator to be used by this class.static voidsetRandomSeed(long new_seed) Sets the seed of this random number generator using a singlelongseed.Methods inherited from class java.util.Random
doubles, doubles, doubles, doubles, ints, ints, ints, ints, longs, longs, longs, longs, next, nextBoolean, nextBytes, nextDouble, nextFloat, nextGaussian, nextInt, nextInt, nextLong, setSeedMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods 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
Sets the base generator to be used by this class.- Parameters:
base_random- ajava.util.Randomsubclass.
-
setRandomSeed
public static void setRandomSeed(long new_seed) Sets the seed of this random number generator using a singlelongseed.- 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
longseed.
-
getRandom
Returns the instance of Random used by this class.- Returns:
- An object of Random
-
randomInt
public static int randomInt()Generates a random integer between0and1.- Returns:
- a random integer between
0and1.
-
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
loandhi.
-
randomLong
public static long randomLong()Generates a random long between0and1.- Returns:
- a random long between
0and1.
-
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
loandhi.
-
randomFloat
public static float randomFloat()Generates a random float between0and1.- Returns:
- a random float between
0and1.
-
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
loandhi.
-
randomDouble
public static double randomDouble()Generates a random double between0and1.- Returns:
- a random double between
0and1.
-
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
loandhi.
-
randomBoolean
public static boolean randomBoolean()Generates a random boolean.- Returns:
- a random boolean.
-
randomBit
public static int randomBit()Generates a random bit: either0or1.- 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:
trueif a success was found;falseotherwise.
-
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.
-