random.sample with large weighted sample-sets?
On 2/15/2014 11:41 PM, Tim Chase wrote:
> I'm not coming up with the right keywords to find what I'm hunting.
> I'd like to randomly sample a modestly compact list with weighted
> distributions, so I might have
> data = (
> ("apple", 20),
> ("orange", 50),
> ("grape", 30),
If you actually start with date in this form, write the few lines needed
to produce the form below.
data = [
for i in range(10):
r = random.randrange(0, 100)
i = bisect.bisect(data, (r, 'zzzzz')) - 1
It is just coincidence that the sample has exactly the expected
Terry Jan Reedy