You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The documentation does not mention issues related to entries with zero weight.
It would seem logical, that when the weight is integer, but it is zero, that the corresponding entry can never be chosen.
For example, I would assume that the following code cannot fail:
use rand::prelude::*;
pub fn main() {
let list = [1, 2, 3, 0];
assert_ne!(*list.choose_weighted(&mut thread_rng(), |number| *number).unwrap(), 0);
}
And additionally, the same should hold for floating point numbers. But there I am less sure, because depending on the implementation maybe there are issues with rounding errors?
use rand::prelude::*;
pub fn main() {
let list = [1.0, 2.0, 3.0, 0.0];
assert_ne!(*list.choose_weighted(&mut thread_rng(), |number| *number).unwrap(), 0.0);
}