Crates.io | reservoir-sampling |
lib.rs | reservoir-sampling |
version | 0.5.1 |
source | src |
created_at | 2020-12-17 10:23:23.159325 |
updated_at | 2021-04-27 15:14:12.451975 |
description | Implementations of a variety of algorithms for reservoir sampling in Rust. |
homepage | |
repository | https://github.com/DesmondWillowbrook/rs-reservoir-sampling |
max_upload_size | |
id | 323877 |
size | 22,976 |
Crate implementing reservoir sampling, a method for getting random samples from a source in a single pass. Useful in situations where size of source is unknown or very large. Read this article for more information: https://en.wikipedia.org/wiki/Reservoir_sampling
All algorithms implemented here have been taken from this article only.
use reservoir_sampling::unweighted::l;
fn main () {
let mut sampled_arr = vec![0usize; 10];
l(0usize..100, sampled_arr.as_mut_slice());
println!("Sampled array: {:?}", sampled_arr);
}
Functions take:
Iterator
over generic type T
, with no constraints which serves as a stream of data to sample.&mut [T]
) to store sampled dataBy default, functions use rand::thread_rng
to provide RNG.
To use your own RNG which implements rand::RNG
, use functions in reservoir_sampling::core
.
Stabilize weighted
and implement more algorithms.