本文介绍了我应该使用std :: default_random_engine还是应该使用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?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 15:39