[Haskell-cafe] Random Numbers for the beginner ?
Crypt Master
cryptmaster at hotmail.com
Tue Jul 6 15:09:53 EDT 2004
Hi
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:
HasGal> rollDice
HasGal>
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.
Thanks,
C
_________________________________________________________________
Add photos to your e-mail with MSN 8. Get 2 months FREE*.
http://join.msn.com/?page=features/featuredemail
More information about the Haskell-Cafe
mailing list