
On Thu, Jan 15, 2004 at 11:00:24PM +0100, Stefan Reich wrote:
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))))
Sure you can. You can 'split' the random generator getting two new generators. One is used to update the global generator, and you use the second one to generate infinite list of pseudo-random values. drawInts :: Int -> Int -> IO [Int] drawInts x y = getStdRandom split >>= (return . randomR (x, y)) Actually, if you relax the type signature you get a function that's "missing" from Random module: randomRIOs :: (Random a) => (a, a) -> IO [a] randomRIOs r = getStdRandom split >>= (return . randomRs r) Best regards, Tom -- .signature: Too many levels of symbolic links