jeudi 22 décembre 2016

How to make an array of events reflect the real-life probabilities of those events without repeating them in Python

So if the array I made to simulate picking a coloured ball from a bag looked like this:

A = ["Blue", "Green", "Yellow"]

then I could just use the

random.choice()

function to simulate picking one from the bag. But if I had a different amount of coloured balls in the bag (say 3 green, 5 blue and 10 yellow), how could I make the random choice from the array reflect the different probabilities of picking each colour?




Aucun commentaire:

Enregistrer un commentaire