We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 554d331 commit d645952Copy full SHA for d645952
distr_test/tests/weighted.rs
@@ -181,6 +181,7 @@ fn choose_two_weighted_indexed() {
181
test_weights(100, |i| i as f64);
182
test_weights(100, |i| (i as f64).powi(3));
183
test_weights(100, |i| 1.0 / ((i + 1) as f64));
184
+ test_weights(10, |i| ((i + 1) as f64).powi(-8));
185
}
186
187
#[test]
src/seq/index.rs
@@ -392,7 +392,7 @@ where
392
while index < length {
393
let weight = weight(index.as_usize()).into();
394
if weight > 0.0 {
395
- let key = rng.random::<f64>().powf(1.0 / weight);
+ let key = rng.random::<f64>().ln() / weight;
396
candidates.push(Element { index, key });
397
} else if !(weight >= 0.0) {
398
return Err(WeightError::InvalidWeight);
0 commit comments