I have the following code:
Class B {
void generator()
{
boost::mt19937 randgen(static_cast<unsigned int>(std::time(0)));
boost::normal_distribution<float> noise(0,1);
boost::variate_generator<boost::mt19937,
boost::normal_distribution<float> > nD(randgen, noise);
for (int i = 0; i < 100; i++)
{
value = nD();
}
}
};
Class A {
void someFunction()
{
for(int i = 1; i <=3; i++)
{
std::shared_ptr<B> b;
b.reset(new B());
b->generator();
}
}
};
I want to execute the above code several times in a row to create multiple graphs. I also looked at this stackoverflow question , which is similar, but the caution states that when time (0) is used and the member function is called quickly, you will probably still get the same sequence of numbers.
How can I solve this problem?
EDIT: I tried to make randgen static in class B, also tried to make it a global variable in class A, but every time the 3 plots are the same. I also tried GetSystemTime millisecond sowing. Something is missing for me.