Pick weights from the range U[0,1]
- ID
a5485a5- date
2025-01-14 21:58:15+00:00- author
Alex Chan <alex@alexwlchan.net>- parent
66df6d7- message
Pick weights from the range U[0,1] This doesn't affect the statistical distribution or behaviour, but makes it easier to match the code to the Wikipedia description.- changed files
1 file, 2 additions, 2 deletions
Changed files
src/sampling.rs (7200) → src/sampling.rs (7174)
diff --git a/src/sampling.rs b/src/sampling.rs
index 79b356c..3d2d534 100644
--- a/src/sampling.rs
+++ b/src/sampling.rs
@@ -109,9 +109,9 @@ pub fn reservoir_sample<T>(mut items: impl Iterator<Item = T>, k: usize) -> Vec<
sample
}
-/// Create a random weight, i.e. a float selected from a uniform random.
+/// Create a random weight u_i ~ U[0,1]
fn pick_weight() -> f64 {
- rand::thread_rng().gen::<f64>()
+ rand::thread_rng().gen_range(0.0..1.0)
}
#[cfg(test)]