use std::io::{BufReader, BufRead};
use std::fs::File;
use rand::Rng;

const K: usize = 5;

pub fn reservoir_sample<R: Rng>(f: File, mut rng: R) -> String {
    let reader = BufReader::new(f);

    let mut reservoir: [String;K] = Default::default();

    for (i, line) in reader.lines().enumerate() {
        let l = line.unwrap();

        if i < K {
            reservoir[i] = l;
        } else {
            let j = rng.gen_range(0, i);
            if j < K {
                reservoir[j] = l;
            }
        }
    }

    let n = rng.gen_range(0, K);

    reservoir[n].clone()
}

use std::io::{BufReader, BufRead};
use std::fs::File;
use rand::Rng;

const K: usize = 10;

pub fn reservoir_sample<R: Rng>(f: File, mut rng: R) -> String {
    let reader = BufReader::new(f);

    let mut reservoir: [String;K] = Default::default();

    for (i, line) in reader.lines().enumerate() {
        let l = line.unwrap();

        if i < K {
            reservoir[i] = l;
        } else {
            let j = rng.gen_range(0, i);
            if j < K {
                reservoir[j] = l;
            }
        }
    }

    let n = rng.gen_range(0, K);

    reservoir[n].clone()
}

--- 
+++ 
@@ -2,7 +2,7 @@
 use std::fs::File;
 use rand::Rng;
 
-const K: usize = 10;
+const K: usize = 5;
 
 pub fn reservoir_sample<R: Rng>(f: File, mut rng: R) -> String {
     let reader = BufReader::new(f);
Change reservoir size to 5

This accounts for shorter files/sample sets.
