mercredi 25 novembre 2015

Choose between various options using probabilities

I've been trying to determine how to choose between various given options with defined probabilities, what I was working on is generating a random number between 0 and 100 and then compare to the probabilities, but I have many probabilities that have the same percentage. For example: the program consists on a baseball game and I have to choose by probability the result of the player at bat.

No advance: .04
Fly Ball: .04
Error: .02
Infield Single: .03

And so on.

srand(time(NULL));
double num = rand() % 100;

double Prob = 70;
if( num < Prob)
     cout << num << endl;

This is the code I been working with which works fine for one probability, but when it comes to many probabilities and some of those probabilities with the same value it gets complicated.




Aucun commentaire:

Enregistrer un commentaire