Package org.openscience.cdk.math
Class RandomNumbersTool
- java.lang.Object
-
- java.util.Random
-
- org.openscience.cdk.math.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 Summary
Constructors Constructor Description RandomNumbersTool()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static 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 RandomgetRandom()Returns the instance of Random used by this class.static longgetRandomSeed()Returns the seed being used by this random number generator.static intrandomBit()Generates a random bit: either0or1.static booleanrandomBoolean()Generates a random boolean.static doublerandomDouble()Generates a random double between0and1.static doublerandomDouble(double lo, double hi)Generates a random double between the specified values.static floatrandomFloat()Generates a random float between0and1.static floatrandomFloat(float lo, float hi)Generates a random float between the specified values.static intrandomInt()Generates a random integer between0and1.static intrandomInt(int lo, int hi)Generates a random integer between the specified values.static longrandomLong()Generates a random long between0and1.static longrandomLong(long lo, long hi)Generates a random long between the specified values.static voidsetRandom(Random base_random)Sets 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.
-
-
-
Method Detail
-
setRandom
public static void setRandom(Random base_random)
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
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 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.
-
-