Anonymous user
One of n lines in a file: Difference between revisions
→{{header|Rust}}
Line 1,916:
fn one_of_n<R: Rng>(rng: &mut R, n: usize) -> usize {
(1..n).fold(0, |keep, cand|
} else
keep
}
)
Line 1,924 ⟶ 1,925:
fn main() {
let mut dist = [0; LINES];
let mut rng = thread_rng();
for _ in 0..1_000_000 {
let num = one_of_n(&mut rng,
dist[num] += 1;
}
|