Hi John,<br>When I was first encountered replicateM I found it really hard to understand. So,of course, I am audacious enough to assume that it is hard for you too! <br><br>The code suggested by Brent , 'replicateM 3 foo' is a nicer way of writing the following:<br>
<br>foo = do<br> x <- getStdRandom $ randomR (1,10)<br> y <- getStdRandom $ randomR (1,10)<br> z <- getStdRandom $ randomR (1,10)<br> return [x,y,z]<br><br>Hope this helped.<br>-deech<br><br><div class="gmail_quote">
On Sat, Oct 24, 2009 at 7:05 PM, Brent Yorgey <span dir="ltr"><<a href="mailto:byorgey@seas.upenn.edu">byorgey@seas.upenn.edu</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div><div></div><div class="h5">On Sat, Oct 24, 2009 at 05:59:35PM +0100, John Moore wrote:<br>
> Hi All,<br>
> Can anyone help me I want to produce a list of three random<br>
> numbers for e.g. [7,8,1]<br>
> I tried using x <- getStdRandom $ randomR (1,10) but don't really understand<br>
> this and it only generates one number. Any help greatly appreciated.<br>
<br>
</div></div>replicateM is your friend:<br>
<br>
replicateM :: (Monad m) => Int -> m a -> m [a]<br>
<br>
so if 'foo' produces a single random number, then 'replicateM 3 foo'<br>
produces a list of three.<br>
<br>
-Brent<br>
_______________________________________________<br>
Beginners mailing list<br>
<a href="mailto:Beginners@haskell.org">Beginners@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/beginners" target="_blank">http://www.haskell.org/mailman/listinfo/beginners</a><br>
</blockquote></div><br>