平均 0 とシグマ 1 の正規分布を生成するために、boost::normal_distribution を使用しようとしています。
次のコードは、一部の値が -1 と 1 を超えているか超えているため (そして、そうであってはならない) 機能しません。私が間違っていることを誰かが指摘できますか?
#include <boost/random.hpp>
#include <boost/random/normal_distribution.hpp>
int main()
{
boost::mt19937 rng; // I don't seed it on purpouse (it's not relevant)
boost::normal_distribution<> nd(0.0, 1.0);
boost::variate_generator<boost::mt19937&,
boost::normal_distribution<> > var_nor(rng, nd);
int i = 0; for (; i < 10; ++i)
{
double d = var_nor();
std::cout << d << std::endl;
}
}
私のマシンでの結果は次のとおりです。
0.213436
-0.49558
1.57538
-1.0592
1.83927
1.88577
0.604675
-0.365983
-0.578264
-0.634376
ご覧のとおり、すべての値が -1 と 1 の間にあるわけではありません。
よろしくお願いします!
編集:これは、締め切りがあり、練習を行う前に理論の勉強を避けたときに起こることです.