[Haskell-cafe] Re: a random numbers generator with a good 'split'
Ertugrul Soeylemez
es at ertes.de
Mon Aug 9 09:02:16 EDT 2010
Hello Petr,
the mersenne-random package is quite low-level and uses explicit
destructive update, so it can only be used with the IO monad. Same with
other fast generators like mwc-random. This is incompatible with the
RandomGen and Random classes, which can only model a pure interface.
About splitting a PRNG: A high quality PRNG can be splitted by using
its own output to derive arbitrarily many child states. If the state is
just a number, in many cases you can derive PRNGs by adding a constant.
Greets,
Ertugrul
<deb at pudlak.name> wrote:
>
> Hi cafe.
>
> recently I was looking at various possibilities of generating random
> numbers in Haskell. Apparently, the main problem is the 'split' function
> in the System.Random.RandomGen class. Since it is rarely needed in
> imperative programs, not much is known how to implement it safely. It's
> documentation says:
>
> > The split operation allows one to obtain two distinct random number
> > generators. This is very useful in functional programs (for example,
> > when passing a random number generator down to recursive calls), but
> > very little work has been done on statistically robust implementations
> > of split ([System.Random, System.Random] are the only examples we know
> > of).
>
> I consulted it with a friend, who has done much work in the area of
> random number generators. He suggested that this might be implemented
> using a random number generator with a very large period, such as
> Mersene Twister (MT19937 has a period of 2^19937-1). A pair of splitted
> generators states could be positioned sufficiently far enough from each
> other so that in practice they never reach each other, and in such a way
> that successive splits (in practice) never meet.
>
> I searched Hackage, where I found a few implementations of Mersene
> Twister, but AFAIK no one actually implements neither RandomGen nor
> 'split' alone. I wonder why -- is RandomGen inconvenient or obsolete in
> some way? Or just nobody tried?
>
> With best regards,
> Petr Pudlak
>
> PS: Sorry if you get multiple copies, I had problems sending the mail.
--
nightmare = unsafePerformIO (getWrongWife >>= sex)
http://ertes.de/
More information about the Haskell-Cafe
mailing list