develooper Front page | perl.perl5.porters | Postings from December 2012

Re: [perl #115928] rand() on Windows only uses 15 bits of entropy

Thread Previous | Thread Next
December 15, 2012 18:02
Re: [perl #115928] rand() on Windows only uses 15 bits of entropy
Message ID:
On 14 December 2012 18:24, Craig A. Berry <> wrote:
> On Fri, Dec 14, 2012 at 10:28 AM, Nicholas Clark <> wrote:
>> On Fri, Dec 14, 2012 at 10:06:30AM -0600, Craig A. Berry wrote:
>>> MT Classic stores state in an array of 624, 32-bit integers.
>> Gulp. Something over 2k.
> My reaction as well.  There is TinyMT, which I mentioned way back in
> this thread, that uses only 127 bits of state:
> <>.
> Of course it doesn't provide as much randomness as the full MT.  I
> have no idea how much randomness is enough or how TinyMT compares to
> drand48().  If it compares favorably, that might be the way to go.

I just pushed smoke-me/tinymt32 which merges in the code for the 32
bit implementation of TinyMT.

Personally I think ripping out support for the system RNG would a big
improvement. It was way easier to sidestep the existing logic than it
was to integrate using tinymt32 separately.

There may be missing bits. I have a feeling I have to do something
during interpreter clone that Im not doing yet.


commit e84331211cf28a7345869e4aef4520754a272683
Author: Yves Orton <>
Date:   Sat Dec 15 18:55:28 2012 +0100

    Enable TINYMT32

    Make perl use Tiny MT (32bit) RNG generator.

commit c5edafd44fe5a818fca631fc8a9c03c780b0ab4e
Author: Yves Orton <>
Date:   Sat Dec 15 18:40:33 2012 +0100

    Add support for using Tiny MT, a 128 bit state RNG

    Perl traditionally uses the systems random number generator
    for the rand() function. This means that the behavior of code
    using it is platform dependent. Worse, sometimes the random
    number generator is of poor quality.

    This patch adds support for using the TinyMT random number
    generator (32 bit version) instead. This generator is of relatively high
    quality, uses 128 bits of state and is relatively fast and should be
    portable to all of our build targets.

    Note that this patch does not *enable* using tinym32, to do that
    you need to define TINYMT32 during configure.

    Full details of the algorithm can be obtained at

    Derived from code by Mutsuo Saito and Makoto Matsumoto published under the
    BSD 3-clause license.

    Copyright (c) 2011 Mutsuo Saito, Makoto Matsumoto, Hiroshima
    University and The University of Tokyo. All rights reserved.

perl -Mre=debug -e "/just|another|perl|hacker/"

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About