[Random] Getting normal_distribution<> to work
Dear all, When I run the following simple code, the output is "-1.#IND" in MSVC 2008 and "nan" in GCC 4.4.0. I guess that means something is not initialised yet... So, what's missing here? boost::normal_distribution<double> gen; boost::mt19937 engine; double r = gen(engine); cout << r; TIA, --Hossein
Hi Hossein,
On Wed, Jul 28, 2010 at 10:33 AM, Hossein Haeri
Dear all,
When I run the following simple code, the output is "-1.#IND" in MSVC 2008 and "nan" in GCC 4.4.0. I guess that means something is not initialised yet... So, what's missing here?
boost::normal_distribution<double> gen; boost::mt19937 engine; double r = gen(engine); cout << r;
Looks like you're forgetting to pass both arguments to the
variate_generator -- the item you marked as gen is really a
distribution.
Try the following:
#include "boost/random/mersenne_twister.hpp"
#include "boost/random/normal_distribution.hpp"
#include "boost/random/variate_generator.hpp"
#include <iostream>
int main()
{
boost::normal_distribution<double> dist;
boost::mt19937 engine;
boost::variate_generator
participants (2)
-
Hossein Haeri
-
Nathan Crookston