如果没有提供种子,NumPy 如何为其随机数生成器提供种子? [英] How does NumPy seed its random number generators if no seed is provided?

查看:51
本文介绍了如果没有提供种子,NumPy 如何为其随机数生成器提供种子?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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 documentation. How does NumPy seed its random numbers when no seed is specified?

推荐答案

对于 NumPy 的遗留 numpy.random.* 函数,包括 numpy.random.uniform,一个全局的RandomState 对象初始化为 no使用参数.因为种子没有传递给这个 RandomState,MT19937 BitGenerator 是通过从 /dev/urandom(或 Windows 模拟)中读取数据来初始化的(如果可用)或种子从时钟否则"(https://numpy.org/doc/stable/reference/random/legacy.html#numpy.random.RandomState).

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).

同样,NumPy 较新的 BitGenerator 类,例如 PCG64,默认为新鲜的、不可预测的熵......从操作系统中提取".(例如default_rng).

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).

这篇关于如果没有提供种子,NumPy 如何为其随机数生成器提供种子?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆