[Haskell-cafe] Random question

Evan Laforge qdunkan at gmail.com
Wed Sep 24 17:13:18 EDT 2008

On Wed, Sep 24, 2008 at 2:03 PM, Iain Barnett <iainspeed at gmail.com> wrote:
> Hi,
> I have a function, that produces a random number between two given numbers
> rand :: Int -> Int -> IO Int
> rand low high = getStdRandom (randomR (low,high))
> (Naively) I'd like to write something like
> take (rand 1 10 ) [1..10]

So once you apply those two Ints, the type of the expression is no
longer a function, it's (IO Int), which is an action that produces and
Int.  So you want to do the action 10 times.  For one approach, check
out 'replicate' to make copies of something, and then 'sequence' to
run them and return a list.

More information about the Haskell-Cafe mailing list