module RandomGen where
import System.Random (StdGen, mkStdGen, next)
import State
import Control.Monad
testRandom :: Int -> Int
testRandom i = fst (next (mkStdGen i))
nextBounded :: Int -> StdGen -> (Int, StdGen)
nextBounded bound s = (i `mod` bound, s') where
(i, s') = next s
testBounded x = fst . nextBounded x . mkStdGen
-- | Extract random values of any type
class Arb1 a where
arb1 :: StdGen -> (a, StdGen)
instance Arb1 Int where
arb1 = next
instance Arb1 Bool where
arb1 s = undefined
testArb1 :: Arb1 a => Int -> a
testArb1 i = fst (arb1 (mkStdGen i))
instance (Arb1 a, Arb1 b) => Arb1 (a,b) where
arb1 s = undefined
instance (Arb1 a) => Arb1 [a] where
arb1 s = undefined
type Gen a = State StdGen a
class Arb a where
arb :: Gen a
instance Arb Int where
arb = state next
bounded :: Int -> Gen Int
bounded b = liftM (`mod` b) arb
instance Arb Bool where
arb = undefined
instance (Arb a, Arb b) => Arb (a,b) where
arb = undefined
instance (Arb a) => Arb [a] where
arb = undefined
sample :: Show a => Gen a -> [a]
sample gen = evalState (sequence (replicate 10 gen)) (mkStdGen 932497234)