[Haskell-cafe] Random this! ;-)

Tobias Brandt tob.brandt at googlemail.com
Sun Jul 25 11:48:15 EDT 2010


Look for the function replicateM in the module Control.Monad.

On 25 July 2010 17:39, michael rice <nowgate at yahoo.com> wrote:

> Hi All,
>
> From: http://en.wikibooks.org/wiki/Haskell/Understanding_monads/State
>
>                            Exercises
>
>    1. Implement a function rollNDiceIO :: Int -> IO [Int] that,
>       given an integer, returns a list with that number of pseudo-
>       random integers between 1 and 6.
>
>
> After a lot of learning what not to do, this is the best I could come up
> with.
>
> rollNDiceIO :: Int -> IO [Int]
> rollNDiceIO n = mapM (\x -> randomRIO(1,6)) (replicate n 1)
>
> I know, ugly, but at least I got it to work. What's a better way to
> generate this list?
>
> Michael
>
>
>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20100725/6828f7e7/attachment.html


More information about the Haskell-Cafe mailing list