[Python-ideas] random.choice on non-sequence

Michael Selik mike at selik.org
Tue Apr 19 01:21:46 EDT 2016

On Wed, Apr 13, 2016 at 12:45 PM Guido van Rossum <guido at python.org> wrote:

> On Wed, Apr 13, 2016 at 2:47 AM, Rob Cliffe <rob.cliffe at btinternet.com>
> wrote:
> > Isn't there an inconsistency that random.sample caters to a set by
> > converting it to a tuple, but random.choice doesn't?
> Perhaps because the use cases are different? Over the years I've
> learned that inconsistencies aren't always signs of sloppy thinking --
> they may actually point to deep issues that aren't apparently on the
> surface.
> I imagine the typical use case for sample() to be something that
> samples the population once and then does something to the sample; the
> next time sample() is called the population is probably different
> (e.g. the next lottery has a different set of players).
> But I imagine a fairly common use case for choice() to be choosing
> from the same population over and over, and that's exactly the case
> where the copying implementation you're proposing would be a small
> disaster.

Repeated random sampling from the same population is a common use case
("bootstrapping"). Perhaps the oversight was *allowing* sets as input into
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20160419/6e2f0ec8/attachment.html>

More information about the Python-ideas mailing list