[Haskell-cafe] random library
will.yager at gmail.com
Wed Oct 11 01:30:34 UTC 2017
The best way to generate random values in multiple threads is to safely
split your random generator every time you fork.
In the case of mwc-random, it looks like you will want to do something like
gen' <- initialize =<< (uniformVector gen 32 :: IO (Vector Word32))
forkIO $ ... gen'
There is no good reason to share RNG state across threads. Just use a
separate RNG state for every thread. This is inherently thread-safe and
If you're forking very frequently, you will want to benchmark the effect of
using a more efficient vector type (i.e. Vector.Unboxed instead of Vector)
or fewer elements during initialization.
On Tue, Oct 10, 2017 at 9:06 PM, Kazu Yamamoto <kazu at iij.ad.jp> wrote:
> Hi David,
> Thank you for your reply.
> > I've heard good things about *mwc-random* (https://github.com/bos/mwc-
> > )
> Are there any example code to use mwc-random safely from multiple
> // Kazu
> Haskell-Cafe mailing list
> To (un)subscribe, modify options or view archives go to:
> Only members subscribed via the mailman list are allowed to post.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Haskell-Cafe