module Synthesizer.RandomKnuth (T, cons, ) where
import qualified System.Random as R
newtype T = Cons Int
deriving Show
{-# INLINE cons #-}
cons :: Int -> T
cons = Cons
{-# INLINE factor #-}
factor :: Int
factor = 40692
{-# INLINE modulus #-}
modulus :: Int
modulus = 2147483399
{-# INLINE split #-}
split :: Int
split = succ $ div modulus factor
{-# INLINE splitRem #-}
splitRem :: Int
splitRem = split * factor - modulus
instance R.RandomGen T where
{-# INLINE next #-}
next (Cons s) =
let (sHigh, sLow) = divMod s split
in (s, Cons $ flip mod modulus $
splitRem*sHigh + factor*sLow)
{-# INLINE split #-}
split (Cons s) = (Cons (s*s), Cons (13+s))
{-# INLINE genRange #-}
genRange _ = (1, pred modulus)