Message197507
The proposed patch add two methods to the Random class and two module level functions: weighted_choice() and weighted_choice_generator().
weighted_choice(data) accepts either mapping or sequence and returns a key or index x with probability which is proportional to data[x].
If you need several elements with same distribution, use weighted_choice_generator(data) which returns an iterator which produces random keys or indices of the data. It is more faster than calling weighted_choice(data) repeatedly and is more flexible than generating a list of random values at specified size (as in NumPy). |
|
Date |
User |
Action |
Args |
2013-09-11 22:29:41 | serhiy.storchaka | set | recipients:
+ serhiy.storchaka, tim.peters, rhettinger, mark.dickinson, pitrou, eli.bendersky, aisaac, westley.martinez, madison.may |
2013-09-11 22:29:41 | serhiy.storchaka | set | messageid: <1378938581.71.0.936432714568.issue18844@psf.upfronthosting.co.za> |
2013-09-11 22:29:41 | serhiy.storchaka | link | issue18844 messages |
2013-09-11 22:29:41 | serhiy.storchaka | create | |
|