[Tutor] Get a single random sample

Peter Otten __peter__ at web.de
Fri Sep 9 14:54:03 CEST 2011


Steven D'Aprano wrote:

> # Get ten random samples, sampling with replacement.
> samples = [random.choice(subset) for i in range(10)]

That may include subset items more than once. Use the aptly named

random.sample(subset, 10)

to avoid that.

 




More information about the Tutor mailing list