随机种子需要有多少不同? [英] How different do random seeds need to be?

查看:138
本文介绍了随机种子需要有多少不同?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

考虑这样的代码(Python):

Consider code like this (Python):

import random

for i in [1, 2, 3, 4]:
    random.seed(i)
    randNumbers = [random.rand() for i in range(100)] # initialize a list with 100 random numbers
    doStuff(randNumbers)

我想确保randNumbers在一次调用与另一次调用之间有显着差异.我是否需要确保后续调用之间的种子编号显着不同,或者是否足以确保种子不同(无论如何)?

I want to make sure that randNumbers differ significantly from one call to another. Do I need to make sure the seed numbers differ significantly between the subsequent calls, or is it sufficient that the seeds are different (no matter how)?

致学徒:请意识到上面的代码过于简化

To the pedants: please realize the above code is super-over-simplified

推荐答案

简短答案:避免重新播种,因为在这里您不会买到任何东西.下面是长答案.

Short answer: Avoid the re-seeding, as it doesn't buy you anything here. Long answer below.

这一切都取决于您到底需要什么.在伪随机数生成器初始化的常见缺陷中,概述了线性相关种子( 1,2,3,4绝对是)对于初始化多个PRNG来说是一个不好的选择,至少在用于模拟和不相关结果的时候是不理想的.

That all depends on what exactly you need. In Common defects in initialization of pseudorandom number generators it is outlined that linear dependent seeds (which 1, 2, 3, 4 definitely are) are a bad choice for initializing multiple PRNGs, at least when used for simulation and desiring uncorrelated results.

如果您要做的只是滚动几个骰子,或为不重要的事情生成一些伪随机输入,那么这很可能无关紧要.

If all you do is rolling a few dice, or generating some pseudo-random input for something uncritical, then it very likely doesn't matter.

还请注意,使用PRNG本身的某些类来生成种子在生成线性相关数时会遇到相同的问题(想到的就是LCG).

Note also that using some classes of a PRNG itself for generating seeds have the same problem in generating linear dependent numbers (LCGs spring to mind).

这篇关于随机种子需要有多少不同?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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