public class Lehmer extends 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/vector/scenario generator to produce repeatable experiments.
|
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)
Seedable
public int order()
LinearCongruentialGenerator
order
in interface LinearCongruentialGenerator
public long modulus()
LinearCongruentialGenerator
modulus
in interface LinearCongruentialGenerator
public long nextLong()
nextLong
in interface RandomLongGenerator
long
numberpublic double nextDouble()
RandomNumberGenerator
double
.nextDouble
in interface RandomNumberGenerator
Copyright © 2010-2020 NM FinTech Ltd.. All Rights Reserved.