C++ RNG : how to get different rand generators on different processors?

标签 c++ algorithm random

如何为随机生成器设置种子,以便在不同的处理器上使用不同的数字序列?

我的第一次尝试是使用处理器的等级作为种子。 然后我发现 srand(0) 给出的序列与 srand(1) 相同。

目前,我正在这样做:

srand(time(NULL) + rank)

这种方法可行吗?或者,还有更好的方法? 谢谢

最佳答案

使用 rand() 初始化 time(NULL) 生成不同的种子,并将该种子传递给您的进程/线程。是的,使用不同于 rand() 的东西。

关于C++ RNG : how to get different rand generators on different processors?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39873761/

相关文章:

c++ - “(void) cast”和 “__attributes__”在沉默未使用的参数警告方面有什么功能区别?

c++ - 你如何使用这个数组而不是请求输入?

C# DLLImport 'Complex' 数组返回和参数

algorithm - 二进制相反数

javascript - 随 secret 码生成器 JavaScript

c++ - string::string 构造函数中的奇怪 "Bus error"

algorithm - 如何使用 Scratch 避免指数符号?

javascript - 重新排列彼此太近的点

windows - Windows批处理文件中的 "for"循环中的随机变量没有改变

java - 将 javabean 初始化为随机值的方法