It seems that the definition of split in System.Random is not really
satisfactory.  Imagine a tree-like computation of the form

f gen = {- some expression using b, g1, g2 -}
  where b = fst (random gen) :: Bool
        (gen1, gen2) = split gen
        g1 = f gen1
        g2 = f gen2

Let's look at the first 30 values of b produced along the right side
of the tree:

GHCi> length $ nub [ take 30 . map (fst . random) . iterate (snd . split) $ 
mkStdGen i :: [Bool] | i <- take 10000 . randoms $ mkStdGen 0 ]
10000

Great, we tried 10000 different initial gens and got 10000 different
sequences.  Now let's look at the left side:

GHCi> length $ nub [ take 30 . map (fst . random) . iterate (fst . split) $ 
mkStdGen i :: [Bool] | i <- take 10000 . randoms $ mkStdGen 0 ]
8

This doesn't seem good.

Michael's code (below) is effectively doing iterate (fst . split).

Regards,
Reid Barton

On Sun, Oct 11, 2009 at 04:24:55PM -0700, michael rice wrote:
> main = do
>   gen <- getStdGen
>   coinToss gen
>   gen <- newStdGen
>   main
_______________________________________________
Haskell-Cafe mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to