Boost Mersenne Twister:如何用多个值种子? [英] Boost Mersenne Twister: how to seed with more than one value?

查看:244
本文介绍了Boost Mersenne Twister:如何用多个值种子?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用boost mt19937实现进行模拟。

I'm using the boost mt19937 implementation for a simulation.

模拟需要是可重现的,这意味着存储和潜在地重用RNG种子。我使用windows crypto api生成种子值,因为我需要一个外部源的种子,而不是因为任何特殊的随机性保证。任何模拟运行的输出都将包含RNG种子的注释 - 因此种子需要合理短。另一方面,作为模拟分析的一部分,我将比较几个运行 - 但是为了确保这些运行实际上不同,我需要使用不同的种子 - 因此种子需要

The simulation needs to be reproducible, and that means storing and potentially reusing the RNG seeds later. I'm using the windows crypto api to generate the seed values because I need an external source for the seeds and not because of any particular guarantees of randomness. The output of any simulation run will have a note including the RNG seed - so the seed needs to be reasonably short. On the other hand, as part of the analysis of the simulation, I'll be comparing several runs - but to be sure that these runs are actually different, I'll need to use different seeds - so the seed needs to be long enough to avoid accidental collisions.

我确定64位的播种应该足够了;在大约2 ^ 32次运行之后,碰撞的机会将达到50% - 这个概率足够低,使得由它引起的平均误差对我来说是可以忽略的。使用32位的种子是棘手的;在2 ^ 16次运行后碰撞的机会已经达到50%这是一个有点太可能我的口味。

I've determined that 64-bits of seeding should suffice; the chance of a collision will reach 50% after about 2^32 runs - that probability is low enough that the average error caused by it is negligible to me. Using just 32-bits of seed is tricky; the chance of a collision reaches 50% already after 2^16 runs; and that's a little too likely for my tastes.

不幸的是,boost实现或者使用一个完整的状态向量 - 远远,太长或者一个32位无符号长度

Unfortunately, the boost implementation either seeds with a full state vector - which is far, far too long - or a single 32-bit unsigned long - which isn't ideal.

如何生成超过32位但小于完全状态向量的生成器?我尝试只填充向量或重复种子来填充状态向量,但即使粗略地看一下结果,也会产生不好的结果。

How can I seed the generator with more than 32-bits but less than a full state vector? I tried just padding the vector or repeating the seeds to fill the state vector, but even a cursory glance at the results shows that that generates poor results.

推荐答案

您的假设是错误的。对于模拟,您不需要加密强的种子。事实上,使用种子1,2,3,4等,通常是一个更好的主意。 Mersenne Twister的输出值将不相关,但没有人会质疑您是否挑选了您的种子来获得所需的模拟输出。

Your assumptions are mistaken. For a simulation, you don't need cryptographically strong seeds. In fact, using seeds 1,2,3,4, etcetera is often a better idea. The output values of the Mersenne Twister will be uncorrelated, yet nobody will question whether you cherry-picked your seeds to get desired simulation outputs.

对于有真正需要,一个简单的方法是丢弃生成的第一个(种子>> 32)值。这给你关于log2(种子>> 32)额外的状态位。然而,它只有工作效率,如果你需要一些额外的位。以这种方式添加32位可能太慢。

For other people who do have a real need, one easy way is to discard the first (seed>>32) values generated. This gives you about log2(seed>>32) extra bits of state. However, it only works efficiently if you need a few extra bits. Adding 32 bits this way is probably too slow.

一个更快的算法是为好的随机生成器 生成全状态向量。问题(重复或填充)中提到的解决方案不是那么好,由于在所得状态向量中的有限的随机性。但是如果你从 mersenne_twister(seed1)^ mersenne_twister(seed2)的输出填充初始状态向量,这根本不是问题。

A faster algorithm is to generate the full state vector for the good random generator. The solutions mentioned in the question (repeating or padding) aren't so good due to the limited randomness in the resulting state vector. But if you fill the initial state vector from the output of mersenne_twister(seed1) ^ mersenne_twister(seed2), this is not an issue at all.

这篇关于Boost Mersenne Twister:如何用多个值种子?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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