[issue18844] allow weights in random.choice

Christian Kleineidam report at bugs.python.org
Mon Sep 15 02:39:05 CEST 2014


Christian Kleineidam added the comment:

I like the idea of adding a weights keyword to choice and creating an additional choice_generator() that also takes weights.

A choice_generator() could take a further argument to allow unique choices and be a generator version of sample().

In some cases you want to draw randomly from a sequence till you draw an item that fulfills certain criteria. At the moment neither the sample nor the shuffle method seems to be optimal for that use case.

Given that items are commonly drawn from an urn in math, urn seems a good alternative for choice_generator().

random.urn(data, *, weights=None, unique=False)

----------
nosy: +Christian.Kleineidam

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue18844>
_______________________________________


More information about the Python-bugs-list mailing list