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 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
getRandom()
Returns the instance of Random used by this class.static long
getRandomSeed()
Returns the seed being used by this random number generator.static int
randomBit()
Generates a random bit: either0
or1
.static boolean
randomBoolean()
Generates a random boolean.static double
randomDouble()
Generates a random double between0
and1
.static double
randomDouble(double lo, double hi)
Generates a random double between the specified values.static float
randomFloat()
Generates a random float between0
and1
.static float
randomFloat(float lo, float hi)
Generates a random float between the specified values.static int
randomInt()
Generates a random integer between0
and1
.static int
randomInt(int lo, int hi)
Generates a random integer between the specified values.static long
randomLong()
Generates a random long between0
and1
.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 singlelong
seed.
-
-
-
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.Random
subclass.
-
setRandomSeed
public static void setRandomSeed(long new_seed)
Sets the seed of this random number generator using a singlelong
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 between0
and1
.- Returns:
- a random integer between
0
and1
.
-
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
andhi
.
-
randomLong
public static long randomLong()
Generates a random long between0
and1
.- Returns:
- a random long between
0
and1
.
-
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
andhi
.
-
randomFloat
public static float randomFloat()
Generates a random float between0
and1
.- Returns:
- a random float between
0
and1
.
-
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
andhi
.
-
randomDouble
public static double randomDouble()
Generates a random double between0
and1
.- Returns:
- a random double between
0
and1
.
-
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
andhi
.
-
randomBoolean
public static boolean randomBoolean()
Generates a random boolean.- Returns:
- a random boolean.
-
randomBit
public static int randomBit()
Generates a random bit: either0
or1
.- 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
.
-
-