def sample(self, population, k):

        # Sampling without replacement entails tracking either potential
        # selections (the pool) in a list or previous selections in a
        # dictionary.

        # When the number of selections is small compared to the population,
        # then tracking selections is efficient, requiring only a small
        # dictionary and an occasional reselection.  For a larger number of
        # selections, the pool tracking method is preferred since the list takes
        # less space than the dictionary and it doesn't suffer from frequent
        # reselections.

        n = len(population)
        if not 0 <= k <= n:
            raise ValueError, "sample larger than population"
        random = self.random
        _int = int
        result = [None] * k
        if n < 6 * k:     # if n len list takes less space than a k len dict
            pool = list(population)
            for i in xrange(k):         # invariant:  non-selected at [0,n-i)
                j = _int(random() * (n-i))
                result[i] = pool[j]
                pool[j] = pool[n-i-1]   # move non-selected item into vacancy
        else:
            try:
                n > 0 and (population[0], population[n//2], population[n-1])
            except (TypeError, KeyError):   # handle sets and dictionaries
                population = tuple(population)
            selected = {}
            for i in xrange(k):
                j = _int(random() * n)
                while j in selected:
                    j = _int(random() * n)
                result[i] = selected[j] = population[j]
        return result

## -------------------- real-valued distributions  -------------------

## -------------------- uniform distribution -------------------
Chooses k unique random elements from a population sequence.
dataset/ETHPy150Open babble/babble/include/jython/Lib/random.py/Random.sample