Welcome, guest | Sign In | My Account | Store | Cart
# 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

History

  • revision 3 (20 years ago)
  • previous revisions are not available