什么是perl的线程安全随机数生成器? [英] What is a thread-safe random number generator for perl?
问题描述
核心perl函数rand()并不是线程安全的,因此在线程蒙特卡洛模拟中我需要随机数.
The core perl function rand() is not thread-safe, and I need random numbers in a threaded monte carlo simulation.
我在CPAN上的各种随机数生成器上找不到任何注释(如果有的话)是线程安全的,就很难了,我做的每个Google搜索都使C/C ++/python/anything变得混乱但是perl.有什么建议吗?
I'm having trouble finding any notes in CPAN on the various random-number generators there as to which (if any) are thread-safe, and every google search I do keeps getting cluttered with C/C++/python/anything but perl. Any suggestions?
推荐答案
如果什么都没有改变,它应该打印 If nothing has changed, it should print 您可以使用 Math :: Random :: MT 您可以在每个线程中使用其自己的种子数组实例化一个新的 You can instantiate a new 这篇关于什么是perl的线程安全随机数生成器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!32768
,这完全不适合任何严肃的工作.而且,即使它确实打印出更大的数字,您最好还是坚持使用已知质量良好的PRNG进行仿真.32768
which is utterly unsuitable for any kind of serious work. And, even if it does print a larger number, you're better off sticking with a PRNG with known good qualities for simulation.Math::Random::MT
对象. Merenne Twister 具有良好的仿真性能.Math::Random::MT
object in each thread with its own array of seeds. Mersenne Twister has good properties for simulation.