boost::random::normal_distribution
#include
Jeffrey Brent McBeth wrote:
#include
#include <iostream> int main(int argc, char *argv[]) { boost::mt19937 eng; boost::normal_distribution<> norm(0,1); std::cout << norm(eng) << std::endl; }
Gives me a NaN everytime. Looking at the code, it doesn't really surprise me, as
_r1 = eng(); _r2 = eng(); _cached_rho = sqrt(-result_type(2)*log(result_type(1)-_r2));
would only work if eng were in the range (0,1) with 0 being degenerate, and 1 being undefined.
IMO, you are totally right. normal_distribution<>::operator() should accept any UniformRandomNumberGenerator, and boost::mt19937 fulfills this requirement. The current implementation does not map the value's of this generator into the feasible domain. I checked the current HEAD which also has the same defect.
Looking through the mt19937, that is returning a full UInt32. Perhaps those two eng() should be replaced by uniform_01?
I understand you to replace eng() by invokations of an uniform_01 engine created from the operator's Engine argument. If so, then the proper mapping engine is *not* boost::uniform_01 but something like boost::uniform_real. boost::uniform_01 is an engine adaptor that *copies* it's constructor argument, therefore proper state transfer to the engine argument would not take place. boost::uniform_real has the wanted effect that it directly uses the given engine instance. Since no-one has answered yet, I strongly recommend you to use the boost bug tracking system to loudly signal this defect. Greetings from Bremen, Daniel Krügler
participants (2)
-
Daniel Krügler
-
Jeffrey Brent McBeth