mercredi 31 mai 2017

Generating a random number with probability [duplicate]

This question already has an answer here:

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