This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author serhiy.storchaka
Recipients aisaac, eli.bendersky, madison.may, mark.dickinson, pitrou, rhettinger, serhiy.storchaka, tim.peters, westley.martinez
Date 2013-09-11.22:29:39
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1378938581.71.0.936432714568.issue18844@psf.upfronthosting.co.za>
In-reply-to
Content
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).
History
Date User Action Args
2013-09-11 22:29:41serhiy.storchakasetrecipients: + serhiy.storchaka, tim.peters, rhettinger, mark.dickinson, pitrou, eli.bendersky, aisaac, westley.martinez, madison.may
2013-09-11 22:29:41serhiy.storchakasetmessageid: <1378938581.71.0.936432714568.issue18844@psf.upfronthosting.co.za>
2013-09-11 22:29:41serhiy.storchakalinkissue18844 messages
2013-09-11 22:29:41serhiy.storchakacreate