Class LcgRndInt31
java.lang.Object
io.github.olyutorskii.aletojio.rng.lcg.AbstractLcg
io.github.olyutorskii.aletojio.rng.lcg.LcgRndInt31
- All Implemented Interfaces:
RndInt31
Implementation of 31bit output Linear congruential generator(LCG).
LCG is a commonly used random number generator in the past.
* LCG implementations on CPU without 64-bit remainders often output only 31-bit random numbers.
Recurrence relation sequences : X(n+1) = (X(n) * Mul + Inc) mod Mod
- Mul : Multiplier
- Inc : Increment
- Mod : Modulus
- See Also:
-
Field Summary
Fields inherited from class io.github.olyutorskii.aletojio.rng.lcg.AbstractLcg
MASK_B31, MASK_B32
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionint
Return next random number as 31bit int from LSB without sign-bit.protected int
Calculate result number from seed.Methods inherited from class io.github.olyutorskii.aletojio.rng.lcg.AbstractLcg
getSeed, nextIntImpl, nextSeed, setSeed
-
Constructor Details
-
LcgRndInt31
Constructor.- Multiplier must be 1 or greatrer.
- Increment must be 0 or greatrer.
- Modulus must be 2 or greater.
- Parameters:
mulArg
- multiplierincArg
- incrementmodArg
- modulus- Throws:
IllegalArgumentException
- illegal argument
-
-
Method Details
-
seedToResult
protected int seedToResult()Calculate result number from seed.result(31bit) reflects seed[0:30]
- Specified by:
seedToResult
in classAbstractLcg
- Returns:
- result number
-
nextInt31
public int nextInt31()Return next random number as 31bit int from LSB without sign-bit.Only positive or zero value returned.
* LCG implementations on CPU without 64-bit remainders often output only 31-bit random numbers.
-