-
Notifications
You must be signed in to change notification settings - Fork 432
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
High limit on gen_range is never returned #167
Comments
Rust's ranges exclude the right hand bound normally. You must ask for an inclusive range explicitly : https://doc.rust-lang.org/std/ops/struct.RangeInclusive.html. |
I think this can be closed, as this is the intended behaviour and changing Note that when the rand crate revision lands it is possible to get inclusive ranges with |
Ok, I'll leave this open as a reminder to check the documentation on |
Going through the "guess_number" rust program example and using this line:
let secret_number = rand::thread_rng().gen_range(0, 1);
secret_number will never have a value of 1 (at least not during repeated testing)
Also true for slightly larger range like (0, 5) that the high limit is not returned.
It's probably ok if the high limit is never returned, but the documentation should indicate that the high limit is not inclusive (while the low limit IS inclusive). I think it's closer to user expectations to make them both inclusive. The current behavior does appear to coincide with Python's but is non-intuitive.
Rust 1.19.0
RHEL7 in a VM
The text was updated successfully, but these errors were encountered: