We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
PredefinedRandom's nextInt() function is overflowing. Running this simple test:
nextInt()
RNG.setSelectedRandomGenerator(RngType.PREDEFINED_RANDOM); for (int i = 0; i < 20; i++) { System.out.println(RNG.nextInt()); }
One can see that it will generate -1 many times and only negative numbers. This is indicative of overflow.
-1
The nextInt() function should be fixed as follows:
@Override public int nextInt() { double normalized = (getNextPredefinedNumber() % 1.0); return (int)(Integer.MIN_VALUE + (long)(normalized * ((long)Integer.MAX_VALUE - Integer.MIN_VALUE))); }
The (normalized * range) should be kept long instead of int due to its size.
(normalized * range)
long
int
I will push a pull request for a new algorithm soon and push this change as well. Tell me if you want a separate PR for this change.
PS: I'm also currently working on improving the Point class and a few other things.
Point
The text was updated successfully, but these errors were encountered:
No branches or pull requests
PredefinedRandom's
nextInt()
function is overflowing. Running this simple test:One can see that it will generate
-1
many times and only negative numbers. This is indicative of overflow.The
nextInt()
function should be fixed as follows:The
(normalized * range)
should be keptlong
instead ofint
due to its size.I will push a pull request for a new algorithm soon and push this change as well. Tell me if you want a separate PR for this change.
The text was updated successfully, but these errors were encountered: