pythonnumpyrandomnumpy-random

How a random number is generated in Numpy if I don't use Generator or RandomState?


I have read the Doc of Numpy,but I still don't know how a random number is generated if I don't use Generator or RandomState. As far as I know,we can get a random number from 1 to 10 by

#use RandomState
print(np.random.RandomState().randint(1,10,(1)))
#use Generator
print(np.random.default_rng().randint(1,10,(1)))
#my question
print(np.random.default_rng().integers(1,10,(1)))

So how the random number is generated in the third way?


Solution

  • (This targets the first version of the question)

    There is just a RandomState created globally at start/import/load-time.

    See code

    More to read in this discussion: Public access to global state for numpy.random