[Haskell-cafe] New seed. New random number. Right? Wrong.
michael rice
nowgate at yahoo.com
Thu Oct 8 16:15:55 EDT 2009
I'm entering a new number to make a different seed for my generator each time through the loop, but my resulting numbers are anything but random.
Where am I going wrong?
Michael
=============================
import System.Random
import Control.Monad(when)
main = do
numberString <- getLine
when (not $ null numberString) $ do
let seed = read numberString
let (randNumber, newGen) = randomR (1,6) (mkStdGen seed) :: (Int, StdGen)
in putStrLn $ "Number is " ++ show randNumber
main
=============================
[michael at localhost ~]$ runhaskell zz.hs
12317
Number is 6
12371
Number is 6
37829
Number is 6
8713
Number is 6
71392
Number is 5
29492
Number is 6
41089
Number is 6
28483
Number is 6
78687
Number is 5
40703
Number is 6
86910
Number is 5
15608
Number is 6
56155
Number is 5
31575
Number is 6
72231
Number is 5
51815
Number is 6
20189
Number is 6
71533
Number is 5
17755
Number is 6
91161
Number is 5
[michael at localhost ~]$
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20091008/e03a25bc/attachment.html
More information about the Haskell-Cafe
mailing list