<div dir="ltr">Apologies, I see the stackoverflow link already does that. The first reply on that thread is right that you'd have issues with that approach anyways for thread safety reasons -- so you'll need a lock, and you'll have to test what that does to performance.</div>
<div class="gmail_extra"><br><br><div class="gmail_quote">On Wed, Jan 29, 2014 at 8:56 AM, Gregory Collins <span dir="ltr"><<a href="mailto:greg@gregorycollins.net" target="_blank">greg@gregorycollins.net</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Try using unsafeInterleaveST?.</div><div class="gmail_extra"><div><div class="h5"><br><br><div class="gmail_quote">
On Tue, Jan 28, 2014 at 7:08 PM, Sacha Sokoloski <span dir="ltr"><<a href="mailto:sacha404@gmail.com" target="_blank">sacha404@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Dear Haskellers,<br>
<br>
I'm in a situation where I'd like to generate an infinite list of random elements (basically, I'm simulating stochastic systems). I feel like MWC Random is the fastest RNG available, but when I try to pull the infinite list out of RandST, it obviously doesn't halt, because ST is strict. Someone posted a way around this in this stack overflow thread:<br>


<br>
<a href="https://stackoverflow.com/questions/16248600/parallel-computations-with-fast-randomness-and-purity" target="_blank">https://stackoverflow.com/<u></u>questions/16248600/parallel-<u></u>computations-with-fast-<u></u>randomness-and-purity</a><br>


<br>
Which would fix my problem. My question is though, why isn't ST.Lazy included as a PrimMonad instance anyway? The best answer I can come up with is that, since evaluating the Generator is time dependent, it's best to make it strict to make sure that one's program isn't tapping into /dev/random at arbitrary times.<br>


<br>
In this way the best stackoverflow solution is quite good. It requires one to strictly generate a Seed (since that's the only way to do it), but then converts the ST Monad to the Lazy version to Lazify everything else. However, my understanding of PrimMonad is simply that it's a class of low level monads i.e. IO and ST, so if there's some deeper reason to this, it's beyond me.<br>


<br>
Another question that I'm puzzling over: In the stack overflow solution, they also make an effort to only have to generate the seed a single time. Is this important performance wise? What I suppose this must hinge upon, is whether in saving an ST s Gen to a Seed, the conversion from an immutable to mutable array requires a copy or not. Is that the full extent of the complexity of this? Is the stackoverflow solution ultimately the most efficient? Is using MWC Random to generate infinite lists and efficient solution anyway?<br>


<br>
Thanks for any insight,<br>
<br>
 - Sacha Sokoloski<br>
______________________________<u></u>_________________<br>
Haskell-Cafe mailing list<br>
<a href="mailto:Haskell-Cafe@haskell.org" target="_blank">Haskell-Cafe@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/haskell-cafe" target="_blank">http://www.haskell.org/<u></u>mailman/listinfo/haskell-cafe</a><br>
</blockquote></div><br><br clear="all"><div><br></div></div></div><span class="HOEnZb"><font color="#888888">-- <br>Gregory Collins <<a href="mailto:greg@gregorycollins.net" target="_blank">greg@gregorycollins.net</a>>
</font></span></div>
</blockquote></div><br><br clear="all"><div><br></div>-- <br>Gregory Collins <<a href="mailto:greg@gregorycollins.net" target="_blank">greg@gregorycollins.net</a>>
</div>