I think you want the engine to be a static member of myclass. I'm not sure that this will make any real difference from what you have if you do not need to use the engine in other ways. I inserted a possible solution below.
, gcc (. ), , , , , ( ), , , gcc , [0,1], , .
, gcc 4.4, Ubuntu, , , std:: random_device.
#include <random>
#include <iostream>
#if defined(__GNUC_MINOR__) && (__GNUC_MINOR__ <= 4)
# define uniform_real_distribution uniform_real
#endif
template <typename Generator>
double randomDoubleEngine(Generator& engine, double low_bound, double high_bound)
{
if (low_bound > high_bound){
std::swap(low_bound, high_bound);
}
return std::uniform_real_distribution<double>(low_bound, high_bound)(engine);
}
class myclass
{
double curThreshold;
static std::mt19937 engine;
void doSomething(double a, double b)
{
curThreshold= randomDoubleEngine(engine, a, b);
}
public:
myclass(): curThreshold(0) {}
void doThat(){
doSomething(0,10);
std::cout << "threshold is " << curThreshold << std::endl;
}
};
std::mt19937 myclass::engine=std::mt19937(std::random_device()());
int
main()
{
myclass m;
m.doThat();
m.doThat();
return 0;
}