-
-
Notifications
You must be signed in to change notification settings - Fork 434
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
Range is not inclusive. Not possible to generate Type::MAX values #188
Comments
Wow, a lot of work. @pitdicker already implemented this, it's just that this is part of a major refactor we haven't tried to merge yet. |
Awesome! I'm looking forward to it. Thank you for your work on this crate. |
rfdonnelly
added a commit
to rfdonnelly/rvs
that referenced
this issue
Nov 11, 2017
* Fixes unable to use Rng trait object with range::sample rust-random/rand#190 * Adds support for inclusive range Replace rvs's own RangeInclusive with rand's new Range::new_inclusive rust-random/rand#188
Since #274 available as |
rfdonnelly
added a commit
to rfdonnelly/rvs
that referenced
this issue
Mar 29, 2018
Note that this does not work for floats yet. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Problem
Range
is consistent with Rust ranges but this makes it impossible to generate<T>::max_value()
samples without special cases.Possible Solution
Implement a
RangeInclusive
Implementations
I see two ways of implementing a
RangeInclusive
:Range
uniform_int_distribution
from the C++ standard library.Option 2 is likely the best performance wise. In the meantime, I've implemented Option 1 for u32.
Implementing
RangeInclusive
usingRange
I've included the details for implementing Option 1 here only to show how obtuse it is and to illustrate why something like C++'s
uniform_int_distribution
is needed.Implementing Option 1 requires three cases:
The range [MIN, MAX]
Not possible to generate using
Range
. Use RNG directly.The range [x, MAX] where x > 0
Implement using
Range
[x - 1, MAX) then add 1.The range [x, y] where y < MAX
Implement using
Range
[x, y + 1)Source for Option 1
The text was updated successfully, but these errors were encountered: