boost::normal_distribution funktioniert nicht
-
#include <iostream> #include <boost/random.hpp> using namespace std; using namespace boost; int main() { mt19937 generator(42); normal_distribution<double> boostNormalRand(100,5); cout << "Mittelwert:" << boostNormalRand.mean() << endl; cout << "Standardabweichung: " << boostNormalRand.sigma() << endl; for(int i=0; i<30; ++i) cout << boostNormalRand( generator ) << " "; }
Ergibt keine richtigen Werte (nur -1.#IND). Kann da jemand Unterstützung bieten?
-
Damit sollte es funktionieren.
#include <boost/random.hpp> #include <conio.h> #include <iostream> using namespace std; int main() { boost::mt19937 generator; boost::normal_distribution<> normal_dist(90,5); boost::variate_generator< boost::mt19937&, boost::normal_distribution<> > random(generator, normal_dist); cout << "Mittelwert: " << normal_dist.mean() << endl; cout << "Standardabweichung: " << normal_dist.sigma() << endl; cout << "Varianz: " << normal_dist.sigma()*normal_dist.sigma() << endl << endl; for (int i=0;i<30;++i) cout << random() << endl; getch(); }