
the function
randomRIO :: (a,a) -> IO a
defined in module Random gives you a random number between the two input
parameters (including themselves).
-- Andre
----- Original Message -----
From: Peter Rooney
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 _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe