jenes
Class Random

java.lang.Object
  extended by jenes.MersenneTwisterFast
      extended by jenes.Random
All Implemented Interfaces:
java.io.Serializable

public class Random
extends MersenneTwisterFast

This class provides the random generator used by JENES.

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.

Since:
1.0
Version:
1.2
Author:
Luigi Troiano, Pierpaolo Lombardi, Giuseppe Pascale, Thierry Bodhuin
See Also:
Serialized Form

Field Summary
static long STANDARD_SEED
          The seed used as default
 
Method Summary
static Random getInstance()
          Returns the Random singleton.
 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.
 
Methods inherited from class jenes.MersenneTwisterFast
main, nextBoolean, nextByte, nextBytes, nextChar, nextDouble, nextFloat, nextGaussian, nextInt, nextInt, nextLong, nextShort, setSeed
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

STANDARD_SEED

public static final long STANDARD_SEED
The seed used as default

See Also:
Constant Field Values
Method Detail

getInstance

public static final Random getInstance()
Returns the Random singleton. At the first invocation the Random object is instantiated.

Returns:
the Random instance

setTimeSeed

public final void setTimeSeed()
Sets the current time as Random seed. This method will make the Random sequence of values different run by run.


setStandardSeed

public final void setStandardSeed()
Sets the stardard value as Random seed. This method will assure the Random sequence of values will not change by run. It should be used for debugging purpose only.


nextDouble

public final double nextDouble(double bound)
Returns a random double uniformly distributed within the interval [0,bound[. Please note that bound is excluded.

Parameters:
bound - the upper bound
Returns:
a random double uniformly distributed within [0,bound[

nextDouble

public final double nextDouble(double lowerBound,
                               double upperBound)
Returns a double uniformly distributed within the interval [lowerBound,upperBound[. Please note that the upperBound is excluded.

Parameters:
lowerBound - the interval lower bound
upperBound - the interval upper bound
Returns:
a double uniformly distributed within [lowerBound,upperBound[

nextInt

public final int nextInt(int lowerBound,
                         int upperBound)
Returns a random integer drawn uniformly in the interval [lowerBound, upperBound[. Please note that upperBound is excluded. Thus the integer is between lowerBound and upperBound-1.

Parameters:
lowerBound - the interval lower bound
upperBound - the interval upper bound
Returns:
an integer drawn uniformly from lowerBound to upperBound-1.

nextBoolean

public final boolean nextBoolean(double coin)
Returns a random boolean value.

Parameters:
coin - the probability to have a true value
Returns:
a boolean value