public class Lehmer extends java.lang.Object implements LinearCongruentialGenerator
We take c to be 0 because Marsaglia shows that there is little additional generality when c ≠ 0. There are restrictions placed on the selection of (a, m) and the seed. For example,xi+1 = (a * xi + c) mod m ui+1 = xi+1 / m
Random.next(int) is doing (for a specific pair a and m),
but it computes (ax mod m) in integer arithmetic without overflow under certain conditions.
In addition, it allows customized multiplier and modulus.
This class is the most fundamental building block for all linear random number generation algorithms in this library.| Constructor and Description |
|---|
Lehmer()
Construct a Lehmer (pure) linear congruential generator.
|
Lehmer(long a,
long m,
long seed)
Construct a Lehmer (pure) linear congruential generator.
|
Lehmer(long a,
long m,
long k,
long seed)
Construct a skipping ahead Lehmer (pure) linear congruential generator.
|
| Modifier and Type | Method and Description |
|---|---|
long |
modulus()
Get the modulus of this linear congruential generator.
|
double |
nextDouble()
Get the next random
double. |
long |
nextLong()
All built-in linear random number generators in this library
ultimately call this function to generate random numbers.
|
int |
order()
Get the order of recursion.
|
void |
seed(long... seeds)
Seed the random number generator to produce repeatable sequences.
|
public Lehmer(long a,
long m,
long seed)
a - the multiplierm - the modulusseed - the seed. It should not be zero.public Lehmer(long a,
long m,
long k,
long seed)
Lehmer((a^k)%m, m, seed)
This implementation computes (a^k)%m more efficiently.
Note that a cannot be too big.a - the multiplierm - the modulusk - the exponentseed - the seed. It should not be zero.public Lehmer()
public void seed(long... seeds)
RandomNumberGeneratorseed in interface RandomNumberGeneratorseeds - the seedspublic int order()
LinearCongruentialGeneratororder in interface LinearCongruentialGeneratorpublic long modulus()
LinearCongruentialGeneratormodulus in interface LinearCongruentialGeneratorpublic long nextLong()
nextLong in interface RandomLongGeneratorlong numberpublic double nextDouble()
RandomNumberGeneratordouble.nextDouble in interface RandomNumberGenerator