org.knowceans.util
Class CokusSampler

java.lang.Object
  extended by org.knowceans.util.CokusSampler
Direct Known Subclasses:
CokusDistributionSampler

public class CokusSampler
extends java.lang.Object

CokusSampler is a non-static version of the Cokus Mersenne Twister as a thread-safe (?) class. (Based on the C code used in LDA-C). It is not derived from Random because the ClassLoader interferes with class construction via Random constructors whose logic isn't needed here.

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

Field Summary
static long DEFAULTSEED
           
static long K
          a magic constant
static int M
          a period parameter
static int N
          length of state vector
 
Constructor Summary
CokusSampler()
          initialise with standard MT seed, 4357.
CokusSampler(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
 long nextUnsignedInt()
          returns a long in the numerical interval of an unsigned int.
 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 final int N
length of state vector

See Also:
Constant Field Values

M

public static final int M
a period parameter

See Also:
Constant Field Values

K

public static final long K
a magic constant

See Also:
Constant Field Values
Constructor Detail

CokusSampler

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


CokusSampler

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

Parameters:
i -
Method Detail

main

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

next

public final int next()
returns the next integer

Returns:

nextUnsignedInt

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

Returns:

randDouble

public final 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.


reload

public final int reload()
reload the random number buffer

Returns: