def logsample(fh, num_samples, **kwargs):
    """Use a Reservoir Sampling algorithm
    to sample uniformly random lines from input stream."""
    R = []
    N = num_samples
    
    for i, k in enumerate(fh):
        if i < N:
            R.append(k)
        else:
            r = randint(0,i)
            if r < N:
                R[r] = k

    # Emit output
    for record in R:
        yield record.strip()
dataset/ETHPy150Open adamhadani/logtools/logtools/_sample.py/logsample/original