newbie:: getting random Ints
Thu, 28 Mar 2002 13:27:19 +0100
Peter Rooney wrote:
> 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
> after loading the file, which makes me think i'm missing something!
This looks like you are using Hugs. Given an IO action, it will perform it.
That is different from giving it a non-IO expression, which it will evaluate
In this case, it will simply generate a random number - and throw it away!
You can try
do dice <- rollDice; print dice
rollDice >>= print
(which is essentially the same) instead, which is an IO action that, when
performed, will generate a random number and print it.
If your problem was not knowing what Hugs does when given an IO action, that's
it. But if you don't yet know who to handle IO, you have still some way to go.