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

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


On Wed, Sep 15, 2010 at 1:46 AM, Simon Peyton-Jones
<simonpj at microsoft.com> 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: http://darcs.haskell.org/ghc/compiler/basicTypes/UniqSupply.lhs
>
> Maybe the same would work for Mersenne.
>
> (Yes it uses unsafeInterleaveIO under the hood.)
>
> Simon
>

Here's a go at it: http://hpaste.org/30094/any_randomgen_can_be_splitable

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.

Antoine


More information about the Libraries mailing list