Sampling a population

Roger Miller roger.miller at nova-sol.com
Fri Jun 2 16:51:41 EDT 2006


For your example, since the probabilities are all multiples of 0.01 you
could make a list of 100 elements.  Set one of them to a, 5 of them to
b, 50 of them to c, etc. Then just randomly sample from the table
(which is O(1)). Of course if the probabilities can be arbitrary
floating point values then this won't work. But if you can live with
rounding to 3 or 4 digits this is probably the fastest and easiest
approach.




More information about the Python-list mailing list