JGAP

org.jgap.util
Class randomX

java.lang.Object
  extended by org.jgap.util.randomX
Direct Known Subclasses:
randomHotBits, randomJava, randomLCG, randomLEcuyer, randomMCG

public abstract class randomX
extends java.lang.Object

Abstract superclass for emulations of java.util.Random with various underlying generators. These generators provide a superset of the methods of the built-in Java generator, and allow easy replacement of the low-level byte-stream random generator without the need to reimplement the higher-level calls.

The nature of the data returned by the functions in this class depends upon the generator provided by the class derived from it. If the generator is algorithmic, the data are pseudorandom; if a hardware generator is employed, genuine random data may be obtained. For brevity, in this document, we use random to refer to the data returned, whatever its actual source.

Designed and implemented in July 1996 by John Walker, kelvin@fourmilab.ch.

See Also:
Random

Constructor Summary
randomX()
           
 
Method Summary
 boolean nextBit()
           
abstract  byte nextByte()
          Return next [pseudo]random byte from low level generator.
 void nextByte(byte[] buf)
          Fill an array of bytes with random data.
 void nextByte(byte[] buf, int buflen)
          Fill a portion of an array of bytes with random data.
 double nextDouble()
           
 float nextFloat()
           
 double nextGaussian()
           
 int nextInt()
           
 long nextLong()
           
 short nextShort()
           
 void setSeed()
          Reset when seed changes.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

randomX

public randomX()
Method Detail

setSeed

public void setSeed()
Reset when seed changes. A generator which supports seed must call this method by super.setSeed() when its own setSeed(long) method is called. This allows randomX to discard any buffered data in the nextBit() and nextGaussian() methods so that subsequent calls will immediately reflect the new seed.

If a derived class does not permit specification of a seed (hardware-based generators, for example), it should declare:

private void setSeed(long seed) { }

which will hide the setSeed method from its users and cause a compile-time error if a program attempts to specify a seed.


nextByte

public abstract byte nextByte()
Return next [pseudo]random byte from low level generator. All generators derived from this class must implement nextByte().


nextInt

public int nextInt()
Returns:
the next random, uniformly distributed, int value.

nextLong

public long nextLong()
Returns:
the next random, uniformly distributed, long value.

nextFloat

public float nextFloat()
Returns:
the next random, uniformly distributed, float value, greater than or equal to 0 and less than 1.

nextDouble

public double nextDouble()
Returns:
the next random, uniformly distributed, double value, greater than or equal to 0 and less than 1.

nextGaussian

public double nextGaussian()
Returns:
the next Gaussian (normal, or bell-curve) distributed random value, with mean of 0.0 and standard deviation 1.0.

nextBit

public boolean nextBit()
Returns:
the next random bit, as a boolean.

nextByte

public void nextByte(byte[] buf,
                     int buflen)
Fill a portion of an array of bytes with random data.

Parameters:
buf - array of byte to fill.
buflen - number of bytes to store.

nextByte

public void nextByte(byte[] buf)
Fill an array of bytes with random data.

Parameters:
buf - array of bytes to fill.

nextShort

public short nextShort()
Returns:
the next random, uniformly distributed, short value.

JGAP