|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.knowceans.util.CokusSampler
public class CokusSampler
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.
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 |
---|
public static final long DEFAULTSEED
public static final int N
public static final int M
public static final long K
Constructor Detail |
---|
public CokusSampler()
public CokusSampler(long i)
i
- Method Detail |
---|
public static void main(java.lang.String[] args)
args
- public final int next()
public final long nextUnsignedInt()
public final double randDouble()
public void setSeed(long seed)
public final int reload()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |