www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Different random output for Phobos and Boost

Hello all,

I've started work on implementing some non-uniform random distributions for 
Phobos, as per earlier discussion:
http://forum.dlang.org/thread/mailman.2109.1335315882.4860.digitalmars-d puremagic.com

Since the Phobos std.random architecture is derived strongly from the C++0X 
random number proposals, which in turn derive from Boost.Random, I've been 
comparing the output of the two and noticed that they do not give identical 
output for the same distributions and random seeds.

Compare e.g. the output of the following:

/// randist.d
import std.random, std.stdio;

void main()
     Mt19937 gen;

     foreach(i; 0..10)
         writefln("%.51f", uniform!("[)", double, double)(0.0, 1.0, gen));

to this:

/// randist.cpp
#include <iostream>
#include <iomanip>
#include <boost/random.hpp>

using namespace std;
using namespace boost;

int main(void)
       mt19937 gen;
       uniform_real<double> dist(0.0, 1.0);
       variate_generator<mt19937&, uniform_real<double> > vargen(gen, dist);
       for(size_t i=0; i<10; ++i) {
             double x = vargen();
             cout << i << "\t" << std::setprecision(51) << x << endl;

       return 0;

I find that the generated numbers diverge after about the 8th or 9th decimal

So -- just asking -- should we care?  And if we should, any ideas about what 
might be responsible?

Thanks & best wishes,

     -- Joe
May 04 2012