如果没有提供种子,NumPy 如何为它的随机数生成器播种?

How does NumPy seed its random number generators if no seed is provided?

例如,假设我调用 numpy.random.uniform(0, 1, 10) 而没有调用任何与种子相关的函数。 NumPy 必须使用一些默认种子,但我在文档中找不到它。当没有指定种子时,NumPy 如何播种它的随机数?

对于 NumPy 的遗留 numpy.random.* 函数,包括 numpy.random.uniform,全局 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)。

同样,NumPy 的更新 BitGenerator 类,例如 PCG64,默认使用“新鲜的、不可预测的熵……从 OS 中拉出”作为种子(default_rng 的示例)。