default_rng.integers(2**32) always return 0
See original GitHub issueReproducing code example:
I don’t understand why default_rng.integers(2**32)
always return 0, whereas 2**32-1
, 2**32+1
, 2**40
, etc. return random numbers as expected. The result is a numpy.int64
, so I expected to be able to generate numbers of up 2**64-1
.
$ python3.7 -c 'from numpy.random import default_rng; rng=default_rng(); print([rng.integers(2**32) for _ in range(5)])'
[0, 0, 0, 0, 0]
It’s fine with 2**40
:
$ python3.7 -c 'from numpy.random import default_rng; rng=default_rng(); print([rng.integers(2**40) for _ in range(5)])'
[386296210341, 896689857600, 958588149890, 364800985883, 643738305251]
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:
vstinner@apu$ python3.7
Python 3.7.6 (default, Jan 30 2020, 09:44:41)
[GCC 9.2.1 20190827 (Red Hat 9.2.1-1)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys, numpy; print(numpy.__version__, sys.version)
1.17.4 3.7.6 (default, Jan 30 2020, 09:44:41)
[GCC 9.2.1 20190827 (Red Hat 9.2.1-1)]
Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (7 by maintainers)
Top Results From Across the Web
numpy.random.Generator.integers — NumPy v1.24 Manual
Return random integers from the “discrete uniform” distribution of the specified dtype. If high is None (the default), then results are from 0...
Read more >Good Practice in (Pseudo) Random ... - UCL Computer Science
Avoid setting the seeds to zero or small numbers in general – ... This always returns random data immediately, but with a risk...
Read more >Random-number functions - Stata
Description: uniformly distributed random integer variates on the interval [a, b]. If a or b is nonintegral, runiformint(a,b) returns runiformint(floor(a),.
Read more >Good Practice in (Pseudo) Random Number ... - StudyLib
Avoid setting the seeds to zero or small numbers in general – try to choose large ... This always returns random data immediately,...
Read more >Why is (rand() % anything) always 0 in C++? - Stack Overflow
int r = (((double)rand()) / RAND_MAX) * desired_maximum; ... int rand_lim(int limit) { /* return a random number between 0 and limit ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
The problem is in master, too:
This was probably introduced in https://github.com/numpy/numpy/pull/14777. I’ll take a look.
It turns out the cause is https://github.com/numpy/numpy/pull/14501, which was backported to 1.17.3. I’m working on a fix.