我应该使用std :: default_random_engine还是应该使用std :: mt19937? [英] Should I use std::default_random_engine or should I use std::mt19937?

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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆