Well, I don&#39;t know how many generators you need.&nbsp; But I&#39;m sure you can pass them around in a way that doesn&#39;t leak.<br><br><div><span class="gmail_quote">On 7/31/07, <b class="gmail_sendername">Chad Scherrer</b>
 &lt;<a href="mailto:chad.scherrer@gmail.com">chad.scherrer@gmail.com</a>&gt; wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">Ok, that looks good, but what if I need some random values elsewhere
<br>in the program? This doesn&#39;t return a new generator (and it can&#39;t<br>because you never get to the end of the list). Without using IO or ST,<br>you&#39;d have to thread the parameter by hand or use the State monad,
<br>right? This is where I was leaking space before.<br><br>Actually, this makes me wonder... I think what killed it before was<br>that the state was threaded lazily through the various (= very many)<br>calls. I suppose a State&#39; monad, strict in the state, could help here.
<br>I wonder how performance for this would compare with IO or ST. Might<br>have to try that sometime...<br><br>Chad<br><br>On 7/31/07, Lennart Augustsson &lt;<a href="mailto:lennart@augustsson.net">lennart@augustsson.net
</a>&gt; wrote:<br>&gt; No leak in sight.<br>&gt;<br>&gt;&nbsp;&nbsp; -- Lennart<br>&gt;<br>&gt; import Random<br>&gt; import Array<br>&gt;<br>&gt; randomElts :: RandomGen g =&gt; g -&gt; [a] -&gt; [a]<br>&gt; randomElts _ [] = []<br>
&gt; randomElts g xs = map (a!) rs<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp;where a = listArray (1, n) xs<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; rs = randomRs (1, n) g<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;n = length xs<br>&gt;<br>&gt; main = do<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; g &lt;- getStdGen<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; let xs = randomElts g [10,2,42::Int]
<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; print $ sum $ take 1000000 xs<br>_______________________________________________<br>Haskell-Cafe mailing list<br><a href="mailto:Haskell-Cafe@haskell.org">Haskell-Cafe@haskell.org</a><br><a href="http://www.haskell.org/mailman/listinfo/haskell-cafe">
http://www.haskell.org/mailman/listinfo/haskell-cafe</a><br></blockquote></div><br>