Mark Dickinson added the comment:

[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.

----------
nosy: +tim.peters

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue18844>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to