org.spaceroots.mantissa.random
Class FourTapRandom

java.lang.Object
  extended byjava.util.Random
      extended byorg.spaceroots.mantissa.random.FourTapRandom
All Implemented Interfaces:
Serializable

public class FourTapRandom
extends Random

This class implements a powerful pseudo-random number generator studied by Robert M Ziff.

This generator belongs to the family of Generalized Feedback Shift-Register (GFSR) generators, but uses four feedback taps instead of two, thus greatly improving their quality for Monte-Carlo simulations.

This generator is described in a paper by Robert M. Ziff in 1997: Four-tap shift-register-sequence random-number generators, it is generator 9f (defined as R(471, 1586, 6988, 9689)) of the paper. It has been kindly contributed to mantissa by Bill Maier.

The class is implemented as a specialization of the standard java.util.Random class. This allows to use it in algorithms expecting a standard random generator, and hence benefit from a better generator without code change.

Version:
$Id: FourTapRandom.java 1666 2005-12-15 16:37:55Z luc $
Author:
Bill Maier (java.util.Random specialization by Luc Maisonobe)
See Also:
Serialized Form

Constructor Summary
FourTapRandom()
          Creates a new random number generator.
FourTapRandom(long seed)
          Creates a new random number generator using a single long seed.
 
Method Summary
protected  int next(int bits)
          Generate next pseudorandom number.
 void setSeed(long seed)
          Reinitialize the generator as if just built with the given seed.
 
Methods inherited from class java.util.Random
nextBoolean, nextBytes, nextDouble, nextFloat, nextGaussian, nextInt, nextInt, nextLong
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FourTapRandom

public FourTapRandom()
Creates a new random number generator.

The instance is initialized using the current time as the seed.


FourTapRandom

public FourTapRandom(long seed)
Creates a new random number generator using a single long seed.

Parameters:
seed - the initial seed
Method Detail

setSeed

public void setSeed(long seed)
Reinitialize the generator as if just built with the given seed.

The state of the generator is exactly the same as a new generator built with the same seed.

Parameters:
seed - the initial seed

next

protected int next(int bits)
Generate next pseudorandom number.

This method is the core generation algorithm. As per Random contract, it is used by all the public generation methods for the various primitive types nextBoolean, nextBytes, nextDouble, nextFloat, nextGaussian, nextInt and nextLong.

Parameters:
bits - number of random bits to produce


Copyright © 2001-2007 Luc Maisonobe. All Rights Reserved.