是否需要调用srand()C函数每个线程或每个进程种子随机发生器? [英] Does one need to call srand() C function per thread or per process to seed the randomizer?
本文介绍了是否需要调用srand()C函数每个线程或每个进程种子随机发生器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这个标题说得很多。
PS。这是针对C ++ Windows程序。
PS. This is for C++ Windows program.
推荐答案
根据 srand()
(假设您使用Microsoft的C运行时库)种子是线程本地的,所以你需要调用 srand()
为每个线程使用 rand()
。请注意,在其他实现中可能不是这样。
According to the MSDN documentation on srand()
(assuming you are using Microsoft's C runtime library), the seed is thread-local, so you need to call srand()
for each thread that is using rand()
. Note that this may not be the case in other implementations.
从MSDN引用:
srand函数设置在当前线程中生成一系列伪随机整数的起点。
The srand function sets the starting point for generating a series of pseudorandom integers in the current thread.
这篇关于是否需要调用srand()C函数每个线程或每个进程种子随机发生器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文