[Tutor] Get a single random sample
steve at pearwood.info
Fri Sep 9 15:06:33 CEST 2011
Peter Otten wrote:
> 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.
Hence the "sampling with replacement" comment.
> Use the aptly named
> random.sample(subset, 10)
> to avoid that.
Ah, I didn't know that one! Nice.
More information about the Tutor