Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.
Sign upRandom.float inaccurate #679
Comments
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
process-bot
Aug 7, 2016
Thanks for the issue! Make sure it satisfies this checklist. My human colleagues will appreciate it!
Here is what to expect next, and if anyone wants to comment, keep these things in mind.
process-bot
commented
Aug 7, 2016
|
Thanks for the issue! Make sure it satisfies this checklist. My human colleagues will appreciate it! Here is what to expect next, and if anyone wants to comment, keep these things in mind. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
bugQ
Aug 7, 2016
I was too hasty. I've been informed that Random is already due to be replaced by PCG, and by reviewing code and testing the edge cases, the implementation looks sound (and excludes the upper bound, like previous implementations have).
Feel free to close this.
bugQ
commented
Aug 7, 2016
|
I was too hasty. I've been informed that Feel free to close this. |
bugQ commentedAug 7, 2016
•
edited
Edited 1 time
-
bugQ
edited Aug 7, 2016 (most recent)
The current implementation of
Random.floatgenerates values in a range slightly lower than advertised. The error is approximately 1.16e10, but this means that, for example,Random.float 0 1can produce a negative value, which is probably not intended. The bug can be reproduced by copying the body of the function and replacingnumberwithminIntormaxIntto observe the output.There are two possible solutions, both affecting line 155:
That is, one option excludes the upper bound, and the other includes it. There are cases to be made for either option. Many algorithms can take advantage of the fact that the upper bound is excluded, including my implementation of the standard normal distribution (elm-community/random-extra#2). However, instead of submitting a pull request, I thought I'd ask for comments first.
P.S.
negativeOneToOneis a misnomer, as it seems to be intended to produce numbers between -0.5 and 0.5. The name of the variable doesn't affect the result, of course.