[Haskell-cafe] setting seed for random numbers

Larry E. larrye2000 at gmail.com
Sun Jan 3 12:46:30 EST 2010


I want to set a random seed for a random number generator. I tried
this:
getSeed = do
       time <- getClockTime
       return (ctPicosec (toUTCTime time))

seed  <-  getSeed
randList minval maxval = randomRs (minval,maxval) (mkStdGen seed)


But I get the error:     parse error on input `<-' which refers to
"seed<-getSeed".

Using "seed<-getSeed"  from the  ghci command line works. Why doesn't
it work in a
script?

THe second problem is the seed is of type Integer but mkStdGen wants
an Int. How can I get an Int from an Integer? I tried mod to get the
seed to within range for an int but the result is still of type
Integer how can I coerce Integer to Int when I know result will fit?

Thanks


More information about the Haskell-Cafe mailing list