[Haskell-cafe] Problem with System.Random.randoms

S. Günther h8spawn at googlemail.com
Sun Dec 7 21:16:37 EST 2008


I have a small problem with System.Random.randoms. I need a rather
large number of random numbers but the following program consumes a
huge amount of memory. I terminated it when it used up more than 2 Gb:

module Main where

import System.Random

n :: Int
n = maxBound

main = do
 g <- getStdGen
 print $ length $ take n $ ((randoms g)::[Int])

On the other hand using
 take n $ [1..]
it runs in constant space.
Am I doing something wrong? Or should I just abandon randoms and use
the more primitive functions in System.Random?

Thanks in advance
S. Günther

More information about the Haskell-Cafe mailing list