
Boost Users : 
Subject: [Boostusers] [Random] normal distribution different behaviour 1.55 vs 1.57
From: Thomas M (firespot71_at_[hidden])
Date: 20141218 05:56:10
Hi,
I have just switched an existent project from boost 1.55.0 to 1.57.0 and
my test suites diagnosed a divergence in program (a simulation) results.
I have tracked down the issue to different behaviour in the normal
distribution random variates generator. Below is a simple program (run
under VS 2012, Update 4) that outputs random variates for a uniform and
a normal distribution; comparing the output between 1.55.0 and 1.57.0 it
turns out that the first bunch of uniformly distributed variates is
identical, and then all others variates (both bunches of normally
distributed variates as well as the second bunch of uniformly
distributed variates) diverge.
Neither for 1.56.0 nor 1.57.0 does the changelog list an update to the
random numbers library, so first I am puzzled why the libraries behave
differently (though [Math] has undergone some changes > propagation to
[Random]?). Second, it is not clear to me why for the first bunch of
uniformly distributed variates the results are identical, while for the
second, after normally distributed variates were generated, the are not.
It appears that the generation of normally distributed variates changes
the whole state of the random numbers engine in a different manner [e.g
multiple engine calls ??].
Any insight into what is going on here is much appreciated. And
foremost: Is any of 1.55 or 1.57 bugged, that is one should be clearly
preferred over the other?
many thanks,
Thomas
#include <ostream>
#include <iostream>
#include <fstream>
#include "boost/random.hpp"
void test_rng()
{
typedef boost::mt19937 rnengine_t;
typedef boost::uniform_01<double> uniform_distr_t;
typedef boost::normal_distribution<double> normal_distr_t;
typedef boost::variate_generator<rnengine_t &, uniform_distr_t>
uniform_gen_t;
typedef boost::variate_generator<rnengine_t &, normal_distr_t>
normal_gen_t;
uniform_distr_t uniformDistr;
normal_distr_t normalDistr(0, 1);
rnengine_t rnEngine;
rnEngine.seed(100);
uniform_gen_t uniformGen(rnEngine, uniformDistr);
normal_gen_t normalGen(rnEngine, normalDistr);
std::ofstream outFile("randomNumbers.txt");
outFile.precision(16);
int n = 20;
for (int outer = 0; outer < 2; ++outer)
{
for (int i = 0; i < n; ++i)
outFile << "Uniformdistr variate #" << (n*outer) + i + 1 << ": "
<< uniformGen() << std::endl;
for (int i = 0; i < n; ++i)
outFile << "Normaldistr variate #" << (n*outer) + i + 1 << ": "
<< normalGen() << std::endl;
}
}
int main()
{
test_rng();
return 0;
}
Boostusers list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net