Skip to content Skip to sidebar Skip to footer

How Does NumPy Seed Its Random Number Generators If No Seed Is Provided?

For example, suppose I call numpy.random.uniform(0, 1, 10) without calling any of the seed-related functions. NumPy must be using some default seed, but I couldn't find it in the d

Solution 1:

For NumPy's legacy numpy.random.* functions, including numpy.random.uniform, a global RandomState object initialized with no arguments is used. Because a seed isn't passed to this RandomState, "the MT19937 BitGenerator is initialized by reading data from /dev/urandom (or the Windows analogue) if available or seed from the clock otherwise" (https://numpy.org/doc/stable/reference/random/legacy.html#numpy.random.RandomState).

Likewise, NumPy's newer BitGenerator classes, such as PCG64, are seeded by default with "fresh, unpredictable entropy ... pulled from the OS" (example for default_rng).


Post a Comment for "How Does NumPy Seed Its Random Number Generators If No Seed Is Provided?"