import random
import itertools


def sample_wr(population, k):
    """Chooses k random elements (with replacement) from a population"""

    n = len(population)
    _random, _int = random.random, int  # speed hack
    return [population[_int(_random() * n)] for _ in itertools.repeat(None, k)]