public class MersenneTwister extends java.lang.Object implements RandomNumberGenerator
As a subclass of java.util.Random this class provides a single canonical method next() for generating bits in the pseudo random number sequence. Anyone using this class should invoke the public inherited methods (nextInt(), nextFloat etc.) to obtain values as normal. This class should provide a drop-in replacement for the standard implementation of java.util.Random with the additional advantage of having a far longer period and the ability to use a far larger seed value.
| Constructor and Description |
|---|
MersenneTwister()
Constructor.
|
MersenneTwister(int seed)
Constructor.
|
MersenneTwister(long seed)
Constructor.
|
| Modifier and Type | Method and Description |
|---|---|
int |
next(int numbits)
Returns up to 32 random bits.
|
double |
nextDouble()
Returns the next pseudorandom, uniformly distributed double value
between 0.0 and 1.0 from this random number generator's sequence.
|
void |
nextDoubles(double[] d)
Returns a vector of pseudorandom, uniformly distributed double values
between 0.0 and 1.0 from this random number generator's sequence.
|
int |
nextInt()
Returns the next pseudorandom, uniformly distributed int value
from this random number generator's sequence.
|
int |
nextInt(int n)
Returns a pseudorandom, uniformly distributed int value
between 0 (inclusive) and the specified value (exclusive),
drawn from this random number generator's sequence.
|
long |
nextLong()
Returns the next pseudorandom, uniformly distributed long value
from this random number generator's sequence.
|
void |
setSeed(int seed) |
void |
setSeed(long seed)
Initialize the random generator with a seed.
|
public MersenneTwister()
public MersenneTwister(int seed)
public MersenneTwister(long seed)
public void setSeed(long seed)
RandomNumberGeneratorsetSeed in interface RandomNumberGeneratorpublic void setSeed(int seed)
public int next(int numbits)
RandomNumberGeneratornext in interface RandomNumberGeneratorpublic double nextDouble()
RandomNumberGeneratornextDouble in interface RandomNumberGeneratorpublic void nextDoubles(double[] d)
RandomNumberGeneratornextDoubles in interface RandomNumberGeneratorpublic int nextInt()
RandomNumberGeneratornextInt in interface RandomNumberGeneratorpublic int nextInt(int n)
RandomNumberGeneratornextInt in interface RandomNumberGeneratorpublic long nextLong()
RandomNumberGeneratornextLong in interface RandomNumberGenerator