-
-
Notifications
You must be signed in to change notification settings - Fork 446
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Is the SliceRandom::choose_weighted(...)
method guaranteed to never choose an entry if it has zero weight?
#1243
Comments
SliceRandom::choose_weighted(...)
method guaranteed to not never choose an entry if it has zero weight?SliceRandom::choose_weighted(...)
method guaranteed to never choose an entry if it has zero weight?
So The implementation for |
@ISibboI would a more visible link to the |
A link to But even the I can make a pull request about this the next days if you agree. |
@ISibboI a pull request that:
Would be very welcome! |
…htedIndex` as discussed in rust-random#1243. Additionally fix some minor issues.
…behavior with floats (#1245) * Fix the documentation for `choose_weighted(_mut)` as discussed in #1243. * Mention that elements of zero weight are handled as expected by `WeightedIndex` as discussed in #1243. Additionally fix some minor issues. * Let the second example of `WeightedIndex` use floats to stress that they are handled correctly for the zero case. * Manually indent doc comments.
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:
(playground)
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?
(playground)
The text was updated successfully, but these errors were encountered: