com.internationalnetwork.math.random
Class XORShiftZ

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

public class XORShiftZ
extends Object

The XORShiftZ class is a consistent alternative to Java's built-in java.util.Random class.  Although it doesn't offer all the same methods, the key methods are 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).

This is a modified version of the XOR Shift algorithm because an additional bit is altered after the first three bit shifts is complete.  This is necessary to ensure that values with all bits set or all bits cleared won't be excluded from the sequence (which is one of the short-comings of any XOR Shift algorithms that rely exclusively on XOR operations and a non-zero seed).

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
XORShiftZ(long seed)
          Instantiate a new XORShiftZ object with the specified seed.  The resulting pseudo-random number sequence is of "medium quality" which is an 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

XORShiftZ

public XORShiftZ(long seed)
Instantiate a new XORShiftZ object with the specified seed.  The resulting pseudo-random number sequence is of "medium quality" which is an improvement over the default java.util.Random class.

Parameters:
seed - Seed that the random number generator is initialized with.
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.