samedi 9 janvier 2016

How to implement roulette wheel for picking random objects in python?

In python, I have a list of objects (size of list is >= 2), which have a property called score which has a value which is any float that's >= 0 (no upper bound).

I want to randomly pick 2 different objects from the list, but make sure that there is a higher chance of picking a value that has a higher score. Basically the higher the score the more chance of being picked. I was thinking of doing a roulette style, where I take a sum of all scores, and then getting a perfect of each item where it's percent is its score divided by the total score.

But how do I still pick the 2 objects?

Thanks




Aucun commentaire:

Enregistrer un commentaire