Sample with replacement

Post date: Jun 30, 2015 8:38:44 PM

Sample with replacement is often used when perform statistical test and bootstrapping the original distribution. Here is the Python code from

http://code.activestate.com/recipes/273085-sample-with-replacement/

# credit author(s) of random.py import random def sample_wr(population, k): "Chooses k random elements (with replacement) from a population" n = len(population) _random, _int = random.random, int # speed hack result = [None] * k for i in xrange(k): j = _int(_random() * n) result[i] = population[j] return result