brew install boost
で 1.60.0_2 が入る。(2016/05/14)
/usr/local/Cellar/boost/1.60.0_2/include
/usr/local/Cellar/boost/1.60.0_2/lib
をインクルードパス、ライブラリパスに追加。
Boost - Wikipedia に載ってるコードを動かしてみる。
#include <iostream>
#include <boost/random.hpp>
#include <ctime>
using namespace boost;
double SampleNormal (double mean, double sigma)
{
// 1970年からの秒でシードを一度初期化した
// メルセンヌ・ツイスタ乱数生成器の作成
static mt19937 rng(static_cast<unsigned> (std::time(0)));
// ガウス確率分布を選択
normal_distribution<double> norm_dist(mean, sigma);
// 関数の形で乱数生成器を分布にバインドする。
variate_generator<mt19937&, normal_distribution<double> > normal_sampler(rng, norm_dist);
// 分布からサンプルする。
return normal_sampler();
}
int main(){
double mean = 0.0;
double sigma = 1.0;
for (int i = 0; i< 100; i++){
std::cout << SampleNormal(mean, sigma) << std::endl;
}
}
動いた。どんなライブラリがあるか知らないので、調べる。文字列処理で便利なのがあるとうれしい。