| Crates.io | weighted-sampling |
| lib.rs | weighted-sampling |
| version | 0.1.0 |
| created_at | 2025-11-25 09:11:04.894167+00 |
| updated_at | 2025-11-25 09:11:04.894167+00 |
| description | Weighted reservoir sampling using Algorithm A-Chao |
| homepage | |
| repository | https://gitlab.com/andrzej1_1/weighted-sampling |
| max_upload_size | |
| id | 1949455 |
| size | 4,842 |
= weighted-sampling
Rust library for weighted reservoir sampling using Algorithm A-Chao.
== Usage
use weighted_sampling::WeightedReservoirSampler; use rand::thread_rng;
let mut sampler = WeightedReservoirSampler::new(); let mut rng = thread_rng();
// Process items from a stream. sampler.sample(10, "item1", &mut rng); // weight: 10 sampler.sample(5, "item2", &mut rng); // weight: 5 sampler.sample(15, "item3", &mut rng); // weight: 15
// Get the selected item. if let Some(selected) = sampler.selected() { println!("Selected: {}", selected); }