My problem is that I don't quite get generating random numbers implemented in the code, and want to ask you if everything here's okay - I mean should it generate new random numbers every time I compile the code? Moreover can you please explain me the difference between the three of following:
for(auto someObject:SomeClass)
for(auto &someObject:SomeClass)
and the third is shown in a method below.
Here's a bit of class definition and the method generating random numbers
class DiscretePDFGenerator {
.
.
.
vector<std::shared_ptr<DiscreteProbabilityValue>>probabilities_;
std::random_device seed_;
std::mt19937 rng_;
std::uniform_real_distribution<double> distribution_;
.
.
.
}
std::string DiscretePDFGenerator::generateGrade ()
{
string value;
double rng,sumProbability=0.0;
rng=distribution_(rng_);
for (auto &&probability: probabilities_)
{
sumProbability+=probability->getProbability();
if (rng<sumProbability)
{
value= probability->getValue();
break;
}
}
return value;
}
I want to ask if there's even need to make it double reference or single reference or not even a reference, if you get my point. Sorry if it's a dumb question and thank you for your help!
Aucun commentaire:
Enregistrer un commentaire