|
SuanShu, a Java numerical and statistical library | |||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||
java.lang.Objectcom.numericalmethod.suanshu.stats.random.univariate.uniform.linear.Lehmer
public class Lehmer
Lehmer proposed a general linear congruential generator that generates pseudo-random numbers in [0, 1]. It has this form:
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 Summary | |
|---|---|
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. |
|
| Method Summary | |
|---|---|
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. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
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()
| Method Detail |
|---|
public void seed(long... seeds)
Seedable
seed in interface Seedableseeds - the seedspublic int order()
LinearCongruentialGenerator
order in interface LinearCongruentialGeneratorpublic long modulus()
LinearCongruentialGenerator
modulus in interface LinearCongruentialGeneratorpublic long nextLong()
nextLong in interface RandomLongGeneratorlong numberpublic double nextDouble()
RandomNumberGeneratordouble.
nextDouble in interface RandomNumberGenerator
|
SuanShu, a Java numerical and statistical library | |||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||