random.shuffle(results)
for i, v in enumerate(iterator, samplesize):
    r = random.randint(0, i)
if r < samplesize:
    results[r] = v
return results
Python random sample with a generator iterable iterator