-
-
Notifications
You must be signed in to change notification settings - Fork 10.9k
default_rng.integers(2**32) always return 0 #16066
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
Comments
Probably it uses a 32bit generator in the background for higher speeds, but then casts |
The problem is in master, too:
This was probably introduced in #14777. I'll take a look. |
Thanks @WarrenWeckesser, the problem is also in 1.17, so it may be older than your commit. But I do think by now it goes this deep into the code and you seem to know that part. So great, was just considering to ping Kevin :). |
If we manage, we should try to include the fix in 1.18.4 I think. |
It turns out the cause is #14501, which was backported to 1.17.3. I'm working on a fix. |
Proposed fix is in #16076 |
When the input to Generator.integers was 2**32, the value 2**32-1 was being passed as the `rng` argument to the 32-bit Lemire method, but that method requires `rng` be strictly less then 2**32-1. The fix was to handle 2**32-1 by calling next_uint32 directly. This also works for the legacy code without changing the stream of random integers from `randint`. Closes numpygh-16066.
When the input to Generator.integers was 2**32, the value 2**32-1 was being passed as the `rng` argument to the 32-bit Lemire method, but that method requires `rng` be strictly less then 2**32-1. The fix was to handle 2**32-1 by calling next_uint32 directly. This also works for the legacy code without changing the stream of random integers from `randint`. Closes numpygh-16066.
NumPy 1.18.4 is the first release with the new random number generator policy (NEP 19) that is not affected by bugs gh-16066 or gh-14774. Refs: - https://numpy.org/devdocs/release/1.18.4-notes.html - numpy/numpy#14774 - numpy/numpy#16066
NumPy 1.18.4 is the first release with the new random number generator policy (NEP 19) that is not affected by bugs gh-16066 or gh-14774. Refs: - https://numpy.org/devdocs/release/1.18.4-notes.html - numpy/numpy#14774 - numpy/numpy#16066
NumPy 1.18.4 is the first release with the new random number generator policy (NEP 19) that is not affected by bugs gh-16066 or gh-14774. Refs: - https://numpy.org/devdocs/release/1.18.4-notes.html - numpy/numpy#14774 - numpy/numpy#16066
Reproducing code example:
I don't understand why
default_rng.integers(2**32)
always return 0, whereas2**32-1
,2**32+1
,2**40
, etc. return random numbers as expected. The result is anumpy.int64
, so I expected to be able to generate numbers of up2**64-1
.It's fine with
2**40
:Numpy/Python version information:
I'm running Fedora 31 with python3-3.7.6-2.fc31.x86_64 and python3-numpy-1.17.4-2.fc31.x86_64:
The text was updated successfully, but these errors were encountered: