确定性随机数发生器绑定到实例(线程独立) [英] Deterministic random number generator tied to instance (thread independent)

查看:162
本文介绍了确定性随机数发生器绑定到实例(线程独立)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 srand

rand 在模拟中生成一些确定性的随机数。然而,当在单独的线程上一次运行多个模拟时,单个序列变得混乱并变得不确定,因为所有线程都从同一池中抽取。有没有一个简单的方法来绑定 rand 从一个特定的实例绘制?或者我要切换到 Boost.Random

I use srand and rand to generate some deterministic random numbers in a simulation. However, when running multiple simulations at once on separate threads, the individual sequence gets muddled up and becomes non deterministic, because all threads draw from the same pool. Is there an easy way to "bind" rand to draw from a specific instance? Or would I have to switch to something like Boost.Random?

推荐答案

你的编译器很可能已经有一个很像Boost.Random的东西。

Your compiler most likely already has something very like Boost.Random.

C ++ 0x包括< random>

C++0x includes a <random> header which is based on Boost.Random (with a few tweaks here and there).

在此之前,TR1,一组半标准库已经是一个基于Boost.Random的头文件可用于大多数编译器,其中包含几乎相同的< random> 头。

Before then, TR1, a set of "semi-standard" libraries was available for most compilers as well, which contains nearly the same <random> header.

这篇关于确定性随机数发生器绑定到实例(线程独立)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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