How to use boost normal distribution classes?
- by David Alfonso
Hi all, I'm trying to use boost::normal_distribution in order to generate a normal distribution with mean 0 and sigma 1.
The following code uses boost normal classes. Am I using them correctly?
#include <boost/random.hpp>
#include <boost/random/normal_distribution.hpp>
int main()
{
boost::mt19937 rng; // I don't seed it on purpouse (it's not relevant)
boost::normal_distribution<> nd(0.0, 1.0);
boost::variate_generator<boost::mt19937&,
boost::normal_distribution<> > var_nor(rng, nd);
int i = 0; for (; i < 10; ++i)
{
double d = var_nor();
std::cout << d << std::endl;
}
}
The result on my machine is:
0.213436
-0.49558
1.57538
-1.0592
1.83927
1.88577
0.604675
-0.365983
-0.578264
-0.634376
As you can see all values are not between -1 and 1.
Thank you all in advance!