
Hi Zemyla, It’s fully documented in the haddocks which I have temporarily put here: https://htmlpreview.github.io/?https://raw.githubusercontent.com/idontgetout... https://htmlpreview.github.io/?https://raw.githubusercontent.com/idontgetout.... There was a link to them in the announcement but maybe I should have highlighted it a bit more. Specifically suppose you love permuted congruential generators then
data PCGen = PCGen !Word64 !Word64
stepGen :: PCGen -> (Word32, PCGen) stepGen (PCGen state inc) = let newState = state * 6364136223846793005 + (inc .|. 1) xorShifted = fromIntegral (((state `shiftR` 18) `xor` state) `shiftR` 27) :: Word32 rot = fromIntegral (state `shiftR` 59) :: Word32 out = (xorShifted `shiftR` (fromIntegral rot)) .|. (xorShifted `shiftL` fromIntegral ((-rot) .&. 31)) in (out, PCGen newState inc)
instance RandomGen PCGen where genWord32 = stepGen split _ = error "PCG is not splittable”
And if you prefer a monadic style interface:
(/ 1000) $ sum $ runStateGen_ (PCGen 17 29) $ \g -> replicateM 1000 $ uniformRM (0.0, 1.0) g
0.508595082944005
HTH - let me know if you have any other questions. Dominic Steinitz dominic@steinitz.org http://idontgetoutmuch.org Twitter: @idontgetoutmuch
On 26 May 2020, at 23:47, Zemyla
wrote: And can you explain how to take an existing RNG and write it in this new format?