This question already has an answer here:
- How to pick an item by its probability? 9 answers
I have a set of 5 objects:
{one, two, three, four, five}
I want to write a Java program which has a for loop running a million times.
In every run of the for loop, I will randomly pick an object from above set.
However, I want to ensure that 40% times one should be selected, 15% times two is selected, 25% times three is selected, 15% times four is selected and 5% times five is selected.
How do I generate a random number with above probabilities in java ?
Aucun commentaire:
Enregistrer un commentaire