-
Notifications
You must be signed in to change notification settings - Fork 431
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
gen_range doesn't take a Range #744
Comments
You can use ranges with rng.sample(Uniform::from(0..=4)) NOTE: this isn't an exact copy of |
|
In part it's historical, and since Rust doesn't support function overloading / multi-functions, we can't allow both. Maybe |
@TheIronBorn if |
@hmble there is potentially some performance difference; But is it worth having both |
@dhardy I guess no its not. IMO we can always use |
The +1 trick does not work for cases where the upper bound is the maximum
possible value.
…On Fri, Apr 5, 2019, 17:47 hmble ***@***.***> wrote:
@ I guess no its not. IMO we can always use rng.gen_range(start, end+1).
Is there any case where we cannot use this approach ? If we decide to
implement a method then from_range would be nice method name.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#744 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AACCtEOXITGnsp23H4kJLjSa0Jog0U49ks5vd3AmgaJpZM4bLkVb>
.
|
It seems a good choice to create another method |
While @vks has a theoretical concern, I don't know how much it is a real concern, and there are workarounds (check the upper-bound or use We could add another method like |
I think there are basically two options on this one:
If not for the breaking change, the second option might be better (though would have to see an implementation first). However, I don't think it's enough better to justify this breaking change? There is a third option: keep |
I think we should probably go with option 2 before Rand 1.0. However, for now I think we should spend our budget for breaking changes elsewhere. |
|
Is there a reason https://docs.rs/rand/0.6.5/rand/trait.Rng.html#method.gen_range doesn't take an std::ops::Range? This would be more convenient for specifying inclusive/exclusive boundary behaviors (e.g.
128..=255u8
).The text was updated successfully, but these errors were encountered: