def _pick_n_random(nrandom, generator):
    '\n    Select n random elements from the generator\n    '
    if (not nrandom):
        (yield from generator)
        return
    selected = []
    i = 0
    iterator = iter(generator)
    try:
        for _ in range(nrandom):
            selected.append(next(iterator))
            i += 1
        while True:
            element = next(iterator)
            i += 1
            index_to_substitute = random.randint(0, i)
            if (index_to_substitute < nrandom):
                selected[index_to_substitute] = element
    except StopIteration:
        pass
    for r in selected:
        (yield r)
Select n random elements from the generator
def _pick_n_random(nrandom, generator):
    '\n    \n    '
    if (not nrandom):
        (yield from generator)
        return
    selected = []
    i = 0
    iterator = iter(generator)
    try:
        for _ in range(nrandom):
            selected.append(next(iterator))
            i += 1
        while True:
            element = next(iterator)
            i += 1
            index_to_substitute = random.randint(0, i)
            if (index_to_substitute < nrandom):
                selected[index_to_substitute] = element
    except StopIteration:
        pass
    for r in selected:
        (yield r)