Class Cmwc
java.lang.Object
io.github.olyutorskii.aletojio.rng.mwc.Mwc
io.github.olyutorskii.aletojio.rng.mwc.Cmwc
- All Implemented Interfaces:
RndInt32
Complementary-multiply-with-carry random number generator.
Random sequence X(n) is derived as follows with parameter a(multiplier), b(divisor).
T(n) = a * X(n-r) + C(n-1)
C(n) = T(n) / b
Y(n) = T(n) mod b
X(n) = b - 1 - Y(n)
r is the length of the record that stores past results. "carry" comes from C(n-1).
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected int
funcRndFromTval
(long tVal) Function that takes T-value as an argument and returns random result.Methods inherited from class io.github.olyutorskii.aletojio.rng.mwc.Mwc
funcCarryFromTval, funcTval, getCarry, getOldest, getRecords, nextInt32, pushLatest, setCarry, setSeeds
-
Constructor Details
-
Cmwc
Constructor.- record length must be greater than 0.
- multiplier must be greater than 1.
- divisor must be greater than 1.
If you want 32-bit uniformly distributed random numbers, the divisor must be 2**32, but you can compromise with 2**32 -1.
- Parameters:
recLen
- records lengthmulArg
- multiplierdivArg
- divisor- Throws:
IllegalArgumentException
- illegal argument
-
Cmwc
Constructor.- Default record length = 1024
- Default multiplier value = 987769338
- Default divisor value = 2**32 - 1
* Caution : If you don't provide your entropy to seeds, it takes over million trials until the seed is scrambled.
- Throws:
IllegalArgumentException
- illegal argument- See Also:
-
-
Method Details
-
funcRndFromTval
protected int funcRndFromTval(long tVal) Function that takes T-value as an argument and returns random result.- Overrides:
funcRndFromTval
in classMwc
- Parameters:
tVal
- T-value- Returns:
- random result
-