[Haskell-cafe] Random Numbers for the beginner ?
cryptmaster at hotmail.com
Tue Jul 6 15:09:53 EDT 2004
I have tried I swear, even googled for 45 minutes, but I cant seem to get
random numbers working.
In the documentation is has:
rollDice :: IO Int
rollDice = getStdRandom (randomR (1,6))
But if I type "getStdRandom (randomR (1,6))" into hugs in the context of
module which imports Random, I get get errors.
ERROR - Unresolved overloading
*** Type : (Random a, Num a) => IO a
*** Expression : getStdRandom (randomR (1,6))
Roll dice takes no parameters and returns an IO Int. So in thoery (mine at
least ;-) ) running this as an expresion should work. I should get an IO Int
back from the interpreter ?
So I added RollDice to my module. This doesnt error, but it doesnt return
anything except blank spaces:
Integers or nums should automatically have show correct? So this should show
me something ?
Ultimatly I want to get randomRs infinite list working so I can build
randNums = (take (length popList) [1..])
where the length of pop list is how many random numbers I want. My code
works as it, just need to replace [1..] with some random numbers.
Add photos to your e-mail with MSN 8. Get 2 months FREE*.
More information about the Haskell-Cafe