newbie:: getting random Ints

Peter Rooney pt@panix.com
28 Mar 2002 01:05:47 -0500


hello all,

total newbie to haskell, armed with "the craft of functional
programming".

i can't seem to generate random numbers. i have read this:

http://www.haskell.org/onlinelibrary/random.html

and searched the web and archives, and read thru Random.hs (mostly
over my head), but have been unable to get any combination of
getStdRandom randomR, etc. to work. even the example in the 98 report,

import Random
 
rollDice :: IO Int
rollDice = getStdRandom (randomR (1,6))

gets me:


Main> rollDice
 
Main>

after loading the file, which makes me think i'm missing something!
TCFP has an example of how to do it yourself, but i can see that my
needs are more than met by Random.hs.

my various attempts all look a lot like this:

Main> getStdGen (random 5)
ERROR - Type error in application
*** Expression     : getStdGen (random 5)
*** Term           : getStdGen
*** Type           : IO StdGen
*** Does not match : a -> b
 
could someone post an example of how to generate random integers
within a range?

tia,
peter