Thanks to visit codestin.com
Credit goes to github.com

Skip to content

BUG: random: Generator.integers(2**32) always returned 0. #16090

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

Merged
merged 4 commits into from
Apr 28, 2020

Conversation

charris
Copy link
Member

@charris charris commented Apr 27, 2020

Backport of #16076.

When the input to Generator.integers was 232, the value 232-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 gh-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.
Assert that an invalid value (2**n-1 for n = 8, 16, 32, 64) has not
been passed to the Lemire function.
Add repeatability tests for when the range of the integers is `2**32`
(and `2**32 +/- 1` for good measure) with broadcasting.  The underlying
functions called by Generator.integers and random.randint when the
inputs are broadcast are different than when the inputs are scalars.
@charris charris added this to the 1.18.4 release milestone Apr 27, 2020
@charris charris closed this Apr 28, 2020
@charris charris reopened this Apr 28, 2020
@charris charris merged commit ea0eb1b into numpy:maintenance/1.18.x Apr 28, 2020
@charris charris deleted the backport-16076 branch May 2, 2020 17:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants