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 mark.dickinson
Recipients aisaac, madison.may, mark.dickinson, pitrou, rhettinger, serhiy.storchaka, tim.peters
Date 2013-08-30.14:43:40
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
[Madison May]
>  - Should negative weights cause a ValueError to be raised, or should they be converted to 0s?
>  - Should passing a list full of zeros as the weights arg raise a ValueError or be treated as if no weights arg was passed?

Both those seem like clear error conditions to me, though I think it would be fine if the second condition produced a ZeroDivisionError rather than a ValueError.

I'm not 100% sold on the feature request.  For one thing, the direct implementation is going to be inefficient for repeated sampling, building the table of cumulative sums each time random.choice is called.  A more efficient approach for many use-cases would do the precomputation once, returning some kind of 'distribution' object from which samples can be generated.  (Walker's aliasing method is one route for doing this efficiently, though there are others.)  I agree that this is a commonly needed and commonly requested operation;  I'm just not convinced either that an efficient implementation fits well into the random module, or that it makes sense to add an inefficient implementation.
Date User Action Args
2013-08-30 14:43:41mark.dickinsonsetrecipients: + mark.dickinson, tim.peters, rhettinger, pitrou, aisaac, serhiy.storchaka, madison.may
2013-08-30 14:43:41mark.dickinsonsetmessageid: <>
2013-08-30 14:43:41mark.dickinsonlinkissue18844 messages
2013-08-30 14:43:40mark.dickinsoncreate