RND engines benchs

%u e at ee.com
Fri Feb 18 15:27:39 PST 2011


== Quote from bearophile (bearophileHUGS at lycos.com)'s article
> Timings, n = 100_000_000, seconds, best of 6:
>   Xorshift:   1.08
>   MinstdRand: 1.15
>   Mt19937:    1.92
> DMD 2.052. It seems that compared to MinstdRand, Xorshift is both faster and
gives higher quality outputs :-)
> import std.stdio, std.random;
> void main() {
>     uint r;
>     //auto rnd = Xorshift(1);
>     //auto rnd = Mt19937(1);
>     auto rnd = MinstdRand(1);
>     foreach (i; 0 .. 100_000_000) {
>         r = rnd.front;
>         rnd.popFront();
>     }
>     writeln(r);
> }
> Another interesting engine:
> http://d.puremagic.com/issues/show_bug.cgi?id=5509
> Bye,
> bearophile

What do you think of my 2 sided dice?

bool randBool()
{
    static uint r;
    static size_t n = 32;

    if( n >= 32 ){
        r = rand();
        n = 0;
    }

    return cast(bool)bt( &r, n++ );
}


More information about the Digitalmars-d mailing list