| Safe Haskell | Safe-Inferred | 
|---|---|
| Language | GHC2021 | 
MCG
Documentation
Create a MCG
>>>make 20 04MCG {m = 23, a = 11, x = 5}
>>>make 101_000_000 20240429MCG {m = 101000023, a = 197265, x = 20240430}
period :: MCG -> Word64 Source #
Period of the MCG.
Period is usually a bit larger than asked for, we look for the next prime:
>>>let g = make 9 04>>>period g10
>>>take 22 (unfoldr (Just . next) g)[4,7,3,1,0,5,2,6,8,9,4,7,3,1,0,5,2,6,8,9,4,7]
reject :: Word64 -> MCG -> (Word64, MCG) Source #
Generate next numbers until one less than given bound is generated.
Replacing next with  effectively cuts the period to reject nn:
>>>let g = make 9 04>>>period g10
>>>take 22 (unfoldr (Just . reject 9) g)[4,7,3,1,0,5,2,6,8,4,7,3,1,0,5,2,6,8,4,7,3,1]
if n is close enough to actual period of MCG, the rejection ratio
 is very small.