-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Revert "allow rand from zero value" #6686
Conversation
This reverts commit 6202e37. That commit introduced a bad change: it silenced a valid error for an arbitrary case. `rand(n)` is always equivalent to `rand(0...n)`. `rand(0...0)` even now says "Invalid range for rand: 0...0". `rand(0)` asks for a number >= 0 and < 0. This makes no sense and should obviously be an error for the same reason.
but why rand(0..0) is ok? |
It's "pick a number ≥ 0 and ≤ 0". That's 0. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree, it's definitely an edge case and we should hide a possibility of error. In Ruby it's worse, it acts like rand
(returning a float), which is super strange. Suggesting using an inclusive range is very good.
* Implement Random for BigInt Fixes crystal-lang#5647 * spec typo fix * Move to big_int.cr * Use to_s in spec * Remove special case of zero because it will be removed in crystal-lang#6686
This reverts #3493.
That commit introduced a bad change: it silenced a valid error for an arbitrary case.
Saying "this is useful" while showing wrong code is not an argument; that code should have just used an inclusive range.
rand(n)
is always equivalent torand(0...n)
.rand(0...0)
even now says "Invalid range for rand: 0...0".rand(0)
asks for a number ≥ 0 and < 0. This makes no sense and should obviously be an error for the same reason.