]> granicus.if.org Git - python/commit
SF bug #801342: Bug (documentation or real, your choice) in random.sample.
authorRaymond Hettinger <python@rcn.com>
Sat, 6 Sep 2003 04:25:54 +0000 (04:25 +0000)
committerRaymond Hettinger <python@rcn.com>
Sat, 6 Sep 2003 04:25:54 +0000 (04:25 +0000)
commit66d09f1b3029d9cf975ccf26c437c9fb2605db91
treeb8c031f72f6109de1be68664fc391c9a334a3f28
parentc8b08b446a95694cf246c3fd92c1bc656944d68f
SF bug #801342:  Bug (documentation or real, your choice) in random.sample.

random.sample() uses one of two algorithms depending on the ratio of the
sample size to the population size.  One of the algorithms accepted any
iterable population argument so long as it defined __len__().  The other
had a stronger requirement that the population argument be indexable.

While it met the documentation specifications which insisted that the
population argument be a sequence, it made random.sample() less usable
with sets.  So, the second algorithm was modified to coerce non-indexable
iterables and dictionaries into a tuple before proceeding.
Lib/random.py
Lib/test/test_random.py