boost normal_distribution

Started by
2 comments, last by michael879 17 years, 10 months ago
I search the boost site and google for a way to use this thing but I cant figure it out. operate() returns the gaussian number but its a template that needs some UniformRandomGenerator. anyone know how to use this?
Advertisement
It is not a function "operate()", but an operator overload "operator()". That is, you "call" the object as if it were a function. It is templated, meaning that it accepts (in theory) an argument of any type that supports the operations that the function implementation does with it; the name 'UniformRandomGenerator' is meant to indicate what operations it needs to provide, and what they should do. In this case, you're expected to provide a callable thing (either another object with an operator() overload, or a (non-member or static member) function pointer) to return a random number with a uniform distribution. Plain old std::rand() will do this, as will some other Boost widgets (which will do it "better" - i.e. more random).

Actually, I guessed almost all of that, but that's how these kinds of things normally are designed :)
yea I was thinking about using rand() but I thought I saw somewhere where it looked like it wouldnt accept a function pointer..
ok yea the rand() function may work for normal_distribution but it doesnt work for uniform_distribution because that makes calls to eng.min and eng.max.

This topic is closed to new replies.

Advertisement