org.knowceans.util
Class CokusRandom

java.lang.Object
  extended by java.util.Random
      extended by org.knowceans.util.CokusRandom
All Implemented Interfaces:
java.io.Serializable

public class CokusRandom
extends java.util.Random

CokusRandom is a non-static version of the Cokus Mersenne Twister as a Random subclass. (Based on the C code used in LDA-C).

Note: nextUnsignedInt(), next(), and randDouble() are tested for conformity with Cokus, which means they provide sufficient randomness. The other methods should yet be used with caution, esp. if long random sequences are to be generated (Monte Carlo simulation etc.).

TODO: Esp. next(int) needs to be tested against randomness criteria; suspected Markov property seen in nextBoolean(). As point of approach, randDouble() and next() use the original Cokus algorithm and can be used as a reference to test randomness against the nextDouble() and nextInt() method that use the scaling mechanism of Random in connection with Cokus's next(int) as a random number generator.

Author:
heinrich
See Also:
Serialized Form

Field Summary
static long DEFAULTSEED
           
static long K
          a magic constant
 double lastRand
           
static int M
          a period parameter
static int N
          length of state vector
 
Constructor Summary
CokusRandom()
          initialise with standard MT seed, 4357.
CokusRandom(long i)
          sets the seed (lower half of long taken)
 
Method Summary
static void main(java.lang.String[] args)
           
 int next()
          returns the next integer
 boolean nextBoolean()
           
 void nextBytes(byte[] bytes)
           
 double nextDouble()
           
 float nextFloat()
           
 double nextGaussian()
           
 int nextInt()
           
 int nextInt(int n)
           
 long nextLong()
           
 long nextUnsignedInt()
          returns a long in the numerical interval of an unsigned int.
 long nextUnsignedLong()
           
 double randDouble()
          returns the next double between 0 and 1.
 int reload()
          reload the random number buffer
 void setSeed(long seed)
          Note: only lower half of seed is used.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULTSEED

public static final long DEFAULTSEED
See Also:
Constant Field Values

N

public static int N
length of state vector


M

public static int M
a period parameter


K

public static long K
a magic constant


lastRand

public double lastRand
Constructor Detail

CokusRandom

public CokusRandom()
initialise with standard MT seed, 4357.


CokusRandom

public CokusRandom(long i)
sets the seed (lower half of long taken)

Parameters:
i -
Method Detail

main

public static void main(java.lang.String[] args)

next

public int next()
returns the next integer

Returns:

nextUnsignedInt

public long nextUnsignedInt()
returns a long in the numerical interval of an unsigned int.

Returns:

randDouble

public double randDouble()
returns the next double between 0 and 1.

Returns:

setSeed

public void setSeed(long seed)
Note: only lower half of seed is used.

Overrides:
setSeed in class java.util.Random

reload

public int reload()
reload the random number buffer

Returns:

nextDouble

public double nextDouble()
Overrides:
nextDouble in class java.util.Random

nextBoolean

public boolean nextBoolean()
Overrides:
nextBoolean in class java.util.Random

nextFloat

public float nextFloat()
Overrides:
nextFloat in class java.util.Random

nextGaussian

public double nextGaussian()
Overrides:
nextGaussian in class java.util.Random

nextInt

public int nextInt()
Overrides:
nextInt in class java.util.Random

nextUnsignedLong

public long nextUnsignedLong()

nextLong

public long nextLong()
Overrides:
nextLong in class java.util.Random

nextBytes

public void nextBytes(byte[] bytes)
Overrides:
nextBytes in class java.util.Random

nextInt

public int nextInt(int n)
Overrides:
nextInt in class java.util.Random