Archiv verlassen und diese Seite im Standarddesign anzeigen : boost::random -> NaN
Hi,
hat jemand Erfahrung mit den Boost Libraries und speziell mit deren Random Number Generator!?
Folgendes Stückchen produziert bei mir nämlich nur NaNs (Not a Number)!?
(...)
static mt19937 rng(static_cast<unsigned> (std::time(0)));
normal_distribution<double> norm_dist(0.0, 0.2);
for (u_int i = 0; i < NUM_POINTS; i++) {
std::cout << norm_dist(rng) << std::endl;
}
(...)
Bin für jeden Hinweis dankbar!
Thomas
peschmae
09-09-2008, 06:05
Kannst du mal was kompilierbares posten? Mit includes und in welcher Library das Zeugs ist; hab boost schon ne Weile nicht mehr benutzt (jetzt neuerdings wieder, aber nicht den Teil da... ;))
MfG Peschmä
#include <iostream>
#include <boost/random.hpp>
int main() {
using namespace boost;
static mt19937 rng(static_cast<unsigned> (std::time(0)));
normal_distribution<double> norm_dist(0.0, 0.2);
for (u_int i = 0; i < 10; i++) {
std::cout << norm_dist(rng) << std::endl;
}
}
peschmae
14-09-2008, 08:38
Sorry für die lange Latenzzeit; sowas geht bei mir:
#include <iostream>
#include <ctime>
#include <boost/random.hpp>
int main() {
using namespace boost;
mt19937 generator(std::time(0));
normal_distribution<> dist(0,0.2);
variate_generator<mt19937&, normal_distribution<> > gen(generator, dist);
for (u_int i = 0; i < 10; i++) {
std::cout << gen() << std::endl;
}
}
Das macht dann:
peschmae@sid:/tmp$ ./test
0.169281
-0.129418
-0.282518
-0.323821
0.157712
0.274284
0.328045
0.191488
-0.279004
0.0202775
Vermutlich hattest du ne veraltete Doku oder so? Die Samples die ich da rumliegen habe sehen alle aus wie mein Code.
MfG Peschmä
Das laeuft schon wesentlich besser :) Vielen Dank.
Powered by vBulletin® Version 4.2.5 Copyright ©2024 Adduco Digital e.K. und vBulletin Solutions, Inc. Alle Rechte vorbehalten.