I want to generate a random number in C++ based on known distribution.
Here is the problem. I rolled a dice (say) 6 times, and I record a four for 3 times, and an one for 1 times, and a two for 2 times. So four=3/6, one=1/6, two=2/6
Is there a library function that I could use which generates a random number based on the above distribution?
If not, do you think it is valid for me to simply do
int i= ran()%5;
if (i is in the range of 0 to 2)
{
//PICK FOUR
}
else if (i is in the range of 3 to 4)
{
// PICK ONE
}
else
{
// PICK TWO
}
Aucun commentaire:
Enregistrer un commentaire