Random number generator
Stefan Reich
doc at drjava.de
Thu Jan 15 23:00:24 EST 2004
That's definitely not a message for the bugs list :-)
Please have a look at this page:
http://www.zvon.org/other/haskell/Outputrandom/getStdRandom_f.html
It gives the correct signature for drawInt as you defined it: Int -> Int
-> IO Int
The signature you gave doesn't work because it specifies a pure function
- for the same set of arguments, it must always produce the same result.
How many ints do you want to generate? I don't think it is possible to
generate an infinite lazy list in this case because this interferes with
monad semantics. If you want a fixed number of random ints, try this:
drawInts :: Int -> Int -> Int -> IO [Int]
drawInts num x y = sequence (replicate num (getStdRandom (randomR (x,y))))
-Stefan
Gwoing Yu wrote:
> Hi,
>
> I need some assistances in calling random number generator using 6.0.1
> haskell compiler. To return a list of random int [Int], I have tried
> the following:
>
> drawInt :: Int->Int -> [Int]
> drawInt x y = getStdRandom (randomRs (x,y))
>
> It has a type error. I would appreciate if you know how to fix it.
>
> Thank you in advance.
>
> Tina Yu
> http://www.improvise.ws <http://www.improvise.ws/>
More information about the Glasgow-haskell-users
mailing list