Boost logo

Boost Users :

Subject: Re: [Boost-users] [Random] Getting normal_distribution<> to work
From: Nathan Crookston (nathan.crookston_at_[hidden])
Date: 2010-07-28 12:52:33

Hi Hossein,

On Wed, Jul 28, 2010 at 10:33 AM, Hossein Haeri <powerprogman_at_[hidden]> wrote:
> 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

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::normal_distribution<double> > gen(engine, dist);
  double r = gen();
  std::cout << r;
  return 0;


Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at