64位随机生成器的种子 [英] 64 bits Seeds for random generators

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

问题描述

我当前正在运行具有8个以上管道(线程)的多线程模拟应用程序。这些管道运行非常复杂的代码,该代码取决于种子生成的随机序列。然后将序列简化为单个0/1。

I am currently running a multithreading simulation application with 8+ pipes (threads). These pipes run a very complex code that depends on a random sequence generated by a seed. The sequence is then boiled down to a single 0/1.

我希望在将种子从种子传递到处理管道后,此随机处理具有100%确定性。主线程。因此,我可以在第二次运行中复制结果。

I want this "random processing" to be 100% deterministic after passing a seed to the processing pipe from the main thread. So, I can replicate the results in a second run.

因此,例如:(我已经对此代码进行了编码并且可以正常工作)

So, for example: (I have this coded and it works)

Pipe 1 -> Seed: 123 -> Result: 0
Pipe 2 -> Seed: 123 -> Result: 0
Pipe 3 -> Seed: 589 -> Result: 1

当我需要运行100M或更多这些过程然后平均结果。可能是100M中只有1个是1,其余都是0的情况。
很明显,我无法对32位种子提供给 srand()<的100M随机值进行采样/ code>。

The problem arises when I need to run 100M or more of these processes and then average the results. It may be the case only 1 of the 100M is a 1, and the rest are 0. As it is obvious, I cannot sample 100M random values with 32bit seeds feeding to srand().

是否可以在VS2010中使用64位种子进行srand()播种,或使用等效方法? >

rand()是在2 ^ 32之后重复自身还是不重复(具有某种内部隐藏状态)?

谢谢

推荐答案

您可以使用C ++ 11的随机工具来生成给定大小和种子大小的随机数,尽管此过程有点太复杂,无法在此处进行总结。

You can use C++11's random facilities to generate random numbers of a given size and seed size, though the process is a bit too complicated to summarize here.

例如,您可以构造一个 std :: mersenne_twister< uint64_t,...> 并将其作为种子使用64位整数,然后在指定的分布范围内获取随机数,这似乎正是您想要的。

For example, you can construct an std::mersenne_twister<uint64_t, ...> and seed it with a 64-bit integer, then acquire random numbers within a specified distribution, which seems to be what you're looking for.

这篇关于64位随机生成器的种子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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