我应该使用std :: default_random_engine还是应该使用std :: mt19937? [英] Should I use std::default_random_engine or should I use std::mt19937?
问题描述
当我想使用std :: random生成随机数时,我应该选择哪个引擎? std :: default_random_engine
还是 std :: mt19937
?有什么区别?
when I want to generate random numbers using std::random, which engine should I prefer? the std::default_random_engine
or the std::mt19937
? what are the differences?
推荐答案
For lightweight randomnes (e.g. games), you could certainly consider default_random_engine
. But if your code depends heavily on quality of randomness (e.g. simulation software), you shouldn't use it, as it gives only minimalistic garantees:
是库实现对生成器的选择,为相对休闲的用户提供至少可接受的引擎行为,不熟练和/或轻量级使用.
另一方面, mt19937
32位mersene扭曲器(或其64位版本的 mt19937_64
)在众所周知的算法,它很好地通过了
The mt19937
32 bits mersene twister (or its 64 bit counterpart mt19937_64
) is on the other side a well known algorithm that passes very well statistical randomness tests. So it's ideal for scientific applications.
但是,如果您的随机数用于安全性(例如加密),则您将不考虑它们.目的.
However, you shall consider neither of them, if your randomn numbers are meant for security (e.g. cryptographic) purpose.
这篇关于我应该使用std :: default_random_engine还是应该使用std :: mt19937?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!