[Haskell-beginners] Re: Getting random values

Volkan YAZICI yazicivo at ttmail.com
Thu Jan 28 03:56:03 EST 2010

On Wed, 27 Jan 2010, Tyler Hayes <tgh at pdx.edu> writes:
> First of all, how do you get a simple random integer in Haskell?

  Prelude Random> getStdGen >>= \g -> let (a, g') = random g in return a

Pay attention to reusing new generator state pointed by g'.

> Second, How does one get a random value from a list of non-integer
> values?

  list !! (length list `mod` random...)


More information about the Beginners mailing list