com.internationalnetwork.math.random
Class MersenneTwister

Object
  extended by com.internationalnetwork.math.random.MersenneTwister

public class MersenneTwister
extends Object

The MersenneTwister class is a consistent 64-bit alternative to Java's built-in java.util.Random class.  Although it doesn't offer all the same methods, the key methods included provide simple and reliable long-sequence pseudo-random number generation.  Steps have been taken in this algorithm to minimize processor overhead, and to ensure the sequence is not repeated for as long as possible (all pseudo-random number generators suffer from the same problem in that the generated sequences eventually repeat).

The algorithm itself uses a series of three eXclusive OR instructions combined with bit-wise Shift operations, all acting on the current seed which doubles as the random number.  Unlike more complicated math operations, which are typically utilized by other pseudo-random number generators, these operations are very fast because they consume fewer CPU cycles (this may be important to game developers, or other developers who are developing other time-sensitive applications).


Field Summary
static String VERSION
          Version number of this Package (read-only).
 
Constructor Summary
MersenneTwister(long... seed)
          Instantiate a new MersenneTwister object with the specified seed, or array of seeds.  The resulting pseudo-random number sequence is of "high quality" which is a big improvement over the default java.util.Random class.
 
Method Summary
 long currentLong()
          Return the current random number.
 int nextInt()
          Return the next random number.
 long nextLong()
          Return the next random number.
 
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

VERSION

public static final String VERSION
Version number of this Package (read-only).

See Also:
Constant Field Values
Constructor Detail

MersenneTwister

public MersenneTwister(long... seed)
Instantiate a new MersenneTwister object with the specified seed, or array of seeds.  The resulting pseudo-random number sequence is of "high quality" which is a big improvement over the default java.util.Random class.

Parameters:
seed - Seed that the random number generator is initialized with.  The total number of seeds may range from 1 to 312, either in the form of an array, or as a series of separate parameters.
Method Detail

currentLong

public long currentLong()
Return the current random number.


nextInt

public int nextInt()
Return the next random number.


nextLong

public long nextLong()
Return the next random number.