Class AbstractLcg
java.lang.Object
io.github.olyutorskii.aletojio.rng.lcg.AbstractLcg
- Direct Known Subclasses:
LcgRndInt31
,LcgRndInt32
Common implementation of Linear congruential generator(LCG).
LCG is a commonly used random number generator in the past.
Recurrence relation sequences : X(n+1) = (X(n) * Mul + Inc) mod Mod
- Mul : Multiplier
- Inc : Increment
- Mod : Modulus
-
Field Summary
Fields -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
AbstractLcg
(long mulArg, long incArg, long modArg) Constructor. -
Method Summary
-
Field Details
-
MASK_B31
protected static final long MASK_B3131bit bitmask.- See Also:
-
MASK_B32
protected static final long MASK_B3232bit bitmask.- See Also:
-
-
Constructor Details
-
AbstractLcg
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
-
nextIntImpl
protected int nextIntImpl()Return next random number as int.Negative value returned if (and only) result bits are 32.
- Returns:
- random number
-
nextSeed
Calculate next seed value from current seed value.- Returns:
- next seed value
- Throws:
IllegalStateException
- seed overflow
-
seedToResult
protected abstract int seedToResult()Calculate result number from seed.- Returns:
- result number
-
setSeed
Set new seed value.- Parameters:
seedArg
- new seed value- Throws:
IllegalArgumentException
- seed too small
-
getSeed
public long getSeed()Get seed value.- Returns:
- seed value
-