This question already has an answer here:
I have problem on MinGW 4.8.1-4 using random number generator.
class RandomGenInt
{
std::random_device rd;
std::mt19937 gen;
std::uniform_int_distribution<d_type::Buint> i_dis;
public:
RandomGenInt(d_type::Bint min,d_type::Bint max)
{
gen.seed(rd());
i_dis=std::uniform_int_distribution<d_type::Buint>(min,max);
}
d_type::Buint generateRandomInt()
{
return i_dis(gen);
}
};
class RandomGenFloat
{
std::random_device rd;
std::mt19937 gen;
std::uniform_real_distribution<d_type::Bfloat> f_dis;
public:
RandomGenFloat(d_type::Buint min=0,d_type::Buint max=1000000000)
{
gen.seed(rd());
f_dis=std::uniform_real_distribution<d_type::Bfloat>(min,max);
}
d_type::Bfloat generateRandomFloat()
{
return f_dis(gen);
}
};
this functions always return the same numbers.
On Linux using gcc the problem doesn't occures... so... what should I do to generate number in c++ on Windows?
Aucun commentaire:
Enregistrer un commentaire