我試圖使用C++ STD TechnicalReport1擴展,產生以下正態分佈的數字,但是這個代碼(改編自this article):只有C++ TR1:如何使用normal_distribution?
mt19937 eng;
eng.seed(SEED);
normal_distribution<double> dist;
// XXX if I use the one below it exits the for loop
// uniform_int<int> dist(1, 52);
for (unsigned int i = 0; i < 1000; ++i) {
cout << "Generating " << i << "-th value" << endl;
cout << dist(eng) << endl;
}
打印1「生成......」日誌消息,那麼永遠不會退出for循環!如果我使用我註釋掉的分佈,它會終止,所以我想知道我在做什麼錯了。任何想法?
非常感謝!
感謝男人,它的作品像一個魅力,但我想知道爲什麼這個引擎的工作,而不是與其他.. – puccio 2009-07-13 10:52:32
顯然唯一的區別是你使用 mt19937號碼生成器,而Jagannath使用std :: tr1 :: ranlux64_base_01。從邏輯上講,我猜這個bug可能是在你的實現mt19937對象(我之前從未聽說過的算法,thx for this :-))中,它不是std庫的一部分。 – 2010-08-06 11:08:24