samedi 9 septembre 2017

randomly select n elements from m categories in python

I want to choose n elements randomly m categories with an weight from w_1 to w_m, is there an elegant way to do this?

Real example to help understand, I'd like to choose 5 fruits randomly from 10 apples, 20 oranges and 30 bananas(i.e., [10, 20, 30]). I might probably get a result of [1, 2, 2].




Aucun commentaire:

Enregistrer un commentaire