www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - RND engines benchs

reply bearophile <bearophileHUGS lycos.com> writes:
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
Feb 18 2011
parent %u <e ee.com> writes:
== Quote from bearophile (bearophileHUGS 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

 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++ ); }
Feb 18 2011