好的主意,种子RNG每次你使用它? [英] Good idea to seed a RNG each time you use it?

查看:161
本文介绍了好的主意,种子RNG每次你使用它?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Mersenne twister算法来洗牌。每次甲板需要洗牌时,我使用时间(NULL)+ deckCutCardNumber,这是用户选择切割牌组的地方。我会得到更好的结果,只从种子的第一只手,并继续生成他们用相同的种子,或者这种方法更随机?

I'm using the Mersenne twister algorithm to shuffle playing cards. Each time the deck needs to be shuffled I seed it with time(NULL) + deckCutCardNumber which is where the user chose to cut the deck. Would I get better results from only seeding it the first hand and continuing to generate them with the same seed or is this method more random?

感谢

推荐答案

假设用户不会弄乱时钟(或者仔细减少它们的截数,只要它们经过的时间),他们永远不会看到反复的PRNG的状态,所以它没有什么区别,你做什么。

Assuming the user doesn't mess with the clock (or carefully reduce their cut number by exactly the time that has passed), they'll never see a repeated state of the PRNG anyway, so it doesn't make much difference what you do. You'll get a reasonable distribution out of the Mersenne Twister from any seed value[*], and at any feasible number of steps after re-seeding.

如果你在Mersenne Twister中找到合适的分布,但是,您可以通过播种与时间,用户选择的数字,加上在重新接种之前从发生器获取的输出结合这两种方法。这将PRNG的当前状态(部分,而不是全部)与新种子数据组合,因此在某种程度上,所有过去时间和切割值(以及PRNG的使用数量)可以影响状态,而不仅仅是最近。以这种方式将更多信息注入种子值可以被认为是更随机的,而种子涉及更少的信息,因此更少的可信值。

If you're keen to reseed, though, you could combine both approaches by seeding with the time, plus the user-chosen number, plus an output taken from the generator just before reseeding. That combines (part of, not all) the current state of the PRNG with the new seed data, so to some degree all of the past times and cut values (and number of uses of the PRNG) can affect the state, not just the most recent. Pouring more information into the seed value in this way could be considered "more random" than a seed involving less information and hence fewer plausible values.

Mersenne Twister特别是如果你可以观察它的600多个输出,那么你可以推断出它的内部状态,并预测剩余的输出,直到它再次接种。然后再次,你可能不会使用MT的应用程序,那种事情很重要:如果你依赖于任何方式的种子,那么你应该使用一个更安全的PRNG开始。显然,如果用户可以预测PRNG中的值,那么对于您的应用程序无所谓,因为用户知道时间和您一样。所有这些告诉你,它不应该怎么种子,只要它没有种子具有完全相同的值,这样两个游戏是相同的。因此,它是否重新种植无关紧要。

The only thing about Mersenne Twister in particular is that if you can observe 600-odd outputs of it, then you can deduce its internal state and predict the rest of the output until it's reseeded. Then again, you probably wouldn't use MT for an application where that sort of thing matters: if you're relying on the reseed in any way then you should probably use a more secure PRNG to begin with. Clearly it doesn't matter for your application if the user can predict the values out of the PRNG, since the user knows the time just as well as you do. All of this tells you that it shouldn't matter how it's seeded, just so long as it isn't seeded with exactly the same value so that two games are identical. Hence it doesn't matter whether it's reseeded either.

[*]这不是严格的真实,有种类的弱种子的MT。但是,只要你在播种时考虑到这一点(例如,在使用之前对种子进行散列,以便坏值不会偶然出现)。

[*] That's not strictly true, there are classes of weak seeds for MT. But as long as you take that into account when seeding (for instance, hash the seed before use so that bad values are unlikely to crop up by chance), you work around that.

这篇关于好的主意,种子RNG每次你使用它?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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