Go back to Richel Bilderbeek's homepage.

Go back to Richel Bilderbeek's C++ page.

 

 

 

 

 

(C++) GetRandomNormal

 

GetRandomNormal is a random number code snippet to draw a random value from a normal distribution.

 

GetRandomNormal uses the Boost library Boost.Random.

 

 

 

 

 

 

#include <boost/random/normal_distribution.hpp>
#include <boost/random/lagged_fibonacci.hpp>
//From http://www.richelbilderbeek.nl/CppGetRandomNormal.htm
double GetRandomNormal(const double mean = 0.0, const double sigma = 1.0)
{
  boost::normal_distribution<double> norm_dist(mean, sigma);
  static boost::lagged_fibonacci19937 engine;
  const double value = norm_dist.operator () <boost::lagged_fibonacci19937>((engine));
  return value;
}

 

 

 

 

 

Go back to Richel Bilderbeek's C++ page.

Go back to Richel Bilderbeek's homepage.

 

Valid XHTML 1.0 Strict

This page has been created by the tool CodeToHtml