Proposal: Move 'split' into a separate class in System.Random

Antoine Latter aslatter at
Wed Sep 15 21:36:11 EDT 2010

On Wed, Sep 15, 2010 at 1:46 AM, Simon Peyton-Jones
<simonpj at> wrote:
> | > (Oh now I see Ivan mentions existing PRNGs that don't (can't?) support
> | > split... that may be a reasonable argument; I'll have to think about it; is
> | > this the main motivation? or just one observation among many?)
> |
> | I think it's the main one; that things like the Mersenne twister can't be
> | made instances of Random has stuck in people's craws for a while.
> In GHC's unique-supply generator we use a trick due to Lennart Augustsson to turn a linear generator (such as the Mersenne twister) into a splittable one.
> Code is here:
> Maybe the same would work for Mersenne.
> (Yes it uses unsafeInterleaveIO under the hood.)
> Simon

Here's a go at it:

I haven't done any benchmarking to see how much overhead there is to
wrapping a random generator with this. I could probably switch to
using atomicModifyIORef, but I don't have much experience with it.

Feedback is welcome.


More information about the Libraries mailing list