Python: How to select 10 random samples n times
Question: **Attempt** :

    
    
    import numpy as np
    import random
    
    with open(r'C:\Python27\Lib\site-packages\visual\examples\hsp.txt') as f:
    
        random.choice(set(f),10)
    
    def repeat(f,N):
        for _ in itertools.repeat(None,N): f()
    

**Error** :

> TypeError: choice() takes exactly 2 arguments (3 given)

It also gives me an invalid syntax if I replaced N with 50.


Answer: From Python Docs

    
    
    random.sample(population, k)
    
    
    Return a k length list of unique elements chosen from the population sequence. Used for random sampling without replacement.
    
    New in version 2.3.
    

Returns a new list containing elements from the population while leaving the
original population unchanged. The resulting list is in selection order so
that all sub-slices will also be valid random samples. This allows raffle
winners (the sample) to be partitioned into grand prize and second place
winners (the subslices).

Members of the population need not be hashable or unique. If the population
contains repeats, then each occurrence is a possible selection in the sample.

To choose a sample from a range of integers, use an xrange() object as an
argument. This is especially fast and space efficient for sampling from a
large population: sample(xrange(10000000), 60).

