public class Random extends MersenneTwisterFast
Random extends the MersenneTwisterFast
class with some methods useful to JENES for obtaining values within a range.
Random implements the singleton design pattern, thus only one instance of Random is available and retrieved by invoking the method getInstance()
.
The random sequence is controlled by the seed. The standard seed assures that the same sequence of random values is produced by different runs. The time based seed, assures that the sequences varies run by run.
Modifier and Type | Field and Description |
---|---|
static long |
STANDARD_SEED
The seed used as default
|
Modifier and Type | Method and Description |
---|---|
static Random |
getInstance()
Returns the Random singleton.
|
static Random |
getInstance(long seed)
Returns the Random sigleton imposing the seed given as argument
|
long |
getSeed()
Return the current seed used for random
|
boolean |
nextBoolean(double coin)
Returns a random boolean value.
|
double |
nextDouble(double bound)
Returns a random double uniformly distributed within the interval [0,bound[.
|
double |
nextDouble(double lowerBound,
double upperBound)
Returns a double uniformly distributed within the interval [lowerBound,upperBound[.
|
int |
nextInt(int lowerBound,
int upperBound)
Returns a random integer drawn uniformly in the interval [lowerBound, upperBound[.
|
void |
setStandardSeed()
Sets the stardard value as Random seed.
|
void |
setTimeSeed()
Sets the current time as Random seed.
|
main, nextBoolean, nextByte, nextBytes, nextChar, nextDouble, nextFloat, nextGaussian, nextInt, nextInt, nextLong, nextShort, setSeed
public static final long STANDARD_SEED
public static Random getInstance()
public static Random getInstance(long seed)
seed
- public final void setTimeSeed()
public final void setStandardSeed()
public long getSeed()
getSeed
in class MersenneTwisterFast
public final double nextDouble(double bound)
bound
- the upper boundpublic final double nextDouble(double lowerBound, double upperBound)
lowerBound
- the interval lower boundupperBound
- the interval upper boundpublic final int nextInt(int lowerBound, int upperBound)
lowerBound
- the interval lower boundupperBound
- the interval upper boundpublic final boolean nextBoolean(double coin)
coin
- the probability to have a true value