问题描述
我使用了一个模拟升压mt19937执行。
I'm using the boost mt19937 implementation for a simulation.
模拟需要可重现,这意味着存储和潜在后来重用RNG种子。我使用Windows加密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.
不幸的是,提升执行要么种子全状态向量 - 这是远远太长 - 或者一个32位无符号长 - 这是不理想
我怎样才能种子有超过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,等等往往是一个更好的主意。梅森倍捻机的输出值将是不相关的,但没有人会质疑你是否樱桃采摘你的种子来获得所需的模拟输出。
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.
这篇关于升压梅森难题:如何与多个值的种子?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!