mercredi 2 septembre 2020

C++ random device outputing same value for each record?

I have a function that uses a random device and mt19937 to produce a random value

int judgeThreshhold()
{
  int threshHold;
  std::random_device rd;
  std::mt19937 generator(rd());
  
  for (auto &judge : aJudge)
  {
    std::normal_distribution<double> distribution(judge.toughness, judge.moodiness);
    threshHold = distribution(generator); //generate threshhold as a random value with toughness as mean and moodiness as standard deviation
  }
  return threshHold;
}

However the threshhold is the same for each judge where it should be different

***Judges Score***
------------------------
Judges Name: Easy Eddie
Judges Threshold: 90
------------------------
------------------------
Judges Name: Irratic Ira
Judges Threshold: 90
------------------------
------------------------
Judges Name: Judicious Jasmine
Judges Threshold: 90
------------------------
------------------------
Judges Name: Resolute Ray
Judges Threshold: 90
------------------------
------------------------
Judges Name: Tough Tom
Judges Threshold: 90
------------------------

As you can see the threshold is the same for each judge where it should be different.




Aucun commentaire:

Enregistrer un commentaire