public class MersenneTwister extends Object implements RandomnessSource
Constructor and Description |
---|
MersenneTwister()
Creates a new RNG and seeds it using the default seeding strategy.
|
MersenneTwister(byte[] seed)
Creates an RNG and seeds it with the specified seed data.
|
Modifier and Type | Method and Description |
---|---|
static int |
convertBytesToInt(byte[] bytes,
int offset)
Take four bytes from the specified position in the specified block and
convert them into a 32-bit int, using the big-endian convention.
|
static int[] |
convertBytesToInts(byte[] bytes)
Convert an array of bytes into an array of ints.
|
RandomnessSource |
copy()
Produces a copy of this RandomnessSource that, if next() and/or nextLong() are called on this object and the
copy, both will generate the same sequence of random numbers from the point copy() was called.
|
byte[] |
getSeed() |
int |
next(int bits)
Using this method, any algorithm that might use the built-in Java Random
can interface with this randomness source.
|
long |
nextLong()
Using this method, any algorithm that needs to efficiently generate more
than 32 bits of random data can interface with this randomness source.
|
public MersenneTwister()
public MersenneTwister(byte[] seed)
seed
- The seed data used to initialize the RNG.public static int convertBytesToInt(byte[] bytes, int offset)
bytes
- The data to read from.offset
- The position to start reading the 4-byte int from.public static int[] convertBytesToInts(byte[] bytes)
bytes
- The data to read from.public byte[] getSeed()
public final int next(int bits)
RandomnessSource
next
in interface RandomnessSource
bits
- the number of bits to be returnedpublic final long nextLong()
RandomnessSource
nextLong
in interface RandomnessSource
public RandomnessSource copy()
copy
in interface RandomnessSource
Copyright © 2012–2016. All rights reserved.