Mark Dickinson <dicki...@gmail.com> added the comment:

Either raising, or treating a zero-weight-sum as undefined behaviour and 
documenting that the sum of the weights should be positive sounds fine to me.

-1 on the suggestion to (deliberately, by documented design) choose at random 
in this case. Mathematically, this situation doesn't make sense: as Tim said, 
it's analogous to choosing from an empty population.

Ex: you have `nred` red balls and `nblue` blue balls in a bag. If you want to 
simulate drawing a single ball from the bag, then

   random.choices(["red", "blue"], [nred, nblue])

does the job. But in the case where `nred = nblue = 0`, the bag is empty and 
it's not possible to draw anything; in that case I'd expect an error. I 
definitely wouldn't expect to get either a red ball or a blue ball (with equal 
probability).

----------

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

Reply via email to