Boost logo

Boost :

From: Bronek Kozicki (brok_at_[hidden])
Date: 2006-08-04 18:34:58


Charles Karney wrote:
> I haven't delved into the code to see where all these problems arise.

interestingly, just two days ago I received similar report regarding "bad"
distribution of uniform_int . Here is test program (comparing number of random
results in top and bottom 10% of range):

#include <iostream>
#include <boost/random/mersenne_twister.hpp>
#include <boost/random/uniform_int.hpp>
#include <boost/random/variate_generator.hpp>

int main() {
    boost::mt19937 rng;
    boost::variate_generator<boost::mt19937&, boost::uniform_int<> >
       gen(rng, boost::uniform_int<>(0,100000000));
    for (int i = 0; i < 20; ++i) {
       int small = 0, large = 0;
       for (int j = 0; j < 100000; ++j) {
          int x = gen();
          if (x < 10000000)
             ++small;
          else if (x >= 100000000 - 10000000)
             ++large;
       }
       std::cout << small << " " << large << std::endl;
    }
}

and output:
10320 9631
10200 9862
10128 9904
10204 9924
10247 9839
10225 9839
10062 9890
10159 9635
10160 9748
10256 9703
10157 9883
10352 9830
10258 9791
10152 9866
10251 9564
10197 9887
10444 9743
10223 10036
10455 10010
10270 9882

author of this test (and original report) successfully used Mersenne Twister
generator in his own project - with much better peformance and distribution.

B.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk