Skip to content

default_rng.integers(2**32) always return 0 #16066

@vstinner

Description

@vstinner

Reproducing 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)]

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions