boost library的下載網址如下:
http://www.boost.org/
此library有提供一些數學distribution的random number generator:
以下是一個lognormal distribution的範例,其他distribution的作法類似:
#include <boost/random.hpp>
double mean_of_lognormal = 1 ;// 這是log normal distribution的mean,也就是 e^{mu+sigma^2/2}
double variance_of_lognormal=1000*mean_of_lognormal*mean_of_lognormal; //這是log normal distribution的variance,
double sigma = sqrt(log(variance_of_lognormal/(mean_of_lognormal*mean_of_lognormal)+1));
double mu = log(mean_of_lognormal) - pow(sigma,2)/2 ;
boost::random::mt19937 rng(static_cast<unsigned int>(std::time(0)));
boost::random::lognormal_distribution<> boost_lognormal(mu,sigma);
double value_of_lognormal = boost_lognormal(rng);