我应该播种随机数生成器吗? [英] Should I seed the random number generator?

查看:55
本文介绍了我应该播种随机数生成器吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

来自文档:

random.seed(a=None, version=2) 初始化随机数生成器.

random.seed(a=None, version=2) Initialize the random number generator.

如果省略 a 或 None,则使用当前系统时间.如果随机源由操作系统提供,它们被使用而不是系统时间(有关详细信息,请参阅 os.urandom() 函数可用性).

If a is omitted or None, the current system time is used. If randomness sources are provided by the operating system, they are used instead of the system time (see the os.urandom() function for details on availability).

但是......如果它真的是随机的......(我认为我读到它使用梅森,所以它非常随机)......播种它有什么意义?无论哪种方式,结果都是不可预测的......对吗?

But...if it's truly random...(and I thought I read it uses Mersenne, so it's VERY random)...what's the point in seeding it? Either way the outcome is unpredictable...right?

推荐答案

如果您希望每次运行都有不同的随机数,那么默认值可能是最好的.如果出于某种原因您需要可重复随机数,例如在测试中,请使用种子.

The default is probably best if you want different random numbers with each run. If for some reason you need repeatable random numbers, in testing for instance, use a seed.

这篇关于我应该播种随机数生成器吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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