设置 random.seed() 以重新创建模拟行为和选择种子的影响 [英] Impact of setting random.seed() to recreate a simulated behaviour and choosing the seed

查看:39
本文介绍了设置 random.seed() 以重新创建模拟行为和选择种子的影响的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用完全确定性的 Python 进行调度模拟.所以,当我有相同的输入和参数时,我总是得到相同的输出.

I am doing a scheduling simulation in python which is full determinstic. So, when I have the same input and parameters I always get the same output.

现在我想随机化模拟的初始起始状态并比较两个(或多个)不同模拟参数的输出.为了比较相同的随机初始起始状态",我想将 random.seed() 设置为一个初始值,对于不同调度程序的所有比较,它应该保持相同.此外,我想查看一个调度程序在不同初始状态下的行为,因此我必须更改 random.seed().我当然必须为所有调度程序执行此操作.

Now I want to randomize the initial starting state of the simulation and compare the output of two (or more) different simulation parameters. To compare the "same randomized initial starting state" I want to set the random.seed() with an initial value, which should stay the same for all comparisions of different schedulers. Furthermore I want to see the behaviour for one scheduler on different initial states so I have to change the random.seed(). This I have to do of course for all schedulers.

现在我的问题是,种子对随机生成器的随机性"有什么影响?例如,我选择种子 1 还是 100 有关系吗?并且因为我想为同一个调度程序使用不同的种子并将其与其他种子进行比较,我可以简单地使用例如种子 1 到 10 还是我的种子必须更随机"?

Now my question is, what impact has the seed on the "randomness" of the random generator? For example does it matter if I choose as a seed 1 or 100? And because I want to use different seeds for the same scheduler and compare it to the other ones, can I simply use e.g. the seeds 1 to 10 or must my seeds be "more random"?

为了澄清起见,我使用随机生成器在不同内核上分配初始任务,并将输出与我的最佳(确定性)初始分配"进行比较.我想用我选择的种子获得广泛的不同分布.

For clarification, I use the random generator for distributing tasks initial on different cores and compare the output to "my optimal (deterministic) initial distribution". I want to get a wide-spread of different distributions with my choosen seeds.

推荐答案

你选择的种子不重要

如果伪随机数生成器制作正确,那么任何种子都应该创建一个随机分布的数字.

If the pseduo-random number generator is made correctly then any seed should create a random distribution of numbers.

来自维基百科:

对于在伪随机数生成器中使用的种子,它不需要是随机的.由于数字生成算法的性质,只要忽略原始种子,算法生成的其余值将遵循伪随机方式的概率分布.

For a seed to be used in a pseudorandom number generator, it does not need to be random. Because of the nature of number generating algorithms, so long as the original seed is ignored, the rest of the values that the algorithm generates will follow probability distribution in a pseudorandom manner.

这篇关于设置 random.seed() 以重新创建模拟行为和选择种子的影响的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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