I've started learning about modern C++ recently and I've been wondering. I know that I can create pseud-random numbers with a Mersenne Twister this way:
std::random_device rnd;
std::mt19937 gen(rnd());
std::uniform_real_distribution<> dist(0.,1.);
So I've found the algorithm std::generate(iterator, iterator, generator) so, my question is. Is there any way to generate random numbers between 0 and 1 with this method and fill the container?
Until now, I've found that if I put for example:
std::generate(v.begin(),v.end(),std::rand); // i know rand() is crap
std::generate(v.begin(),v.end(),std::gen);
These two work fine but numbers between 0. and 1. would be real nice for no specific reason.
Thank you in advance.
Aucun commentaire:
Enregistrer un commentaire