C ++中最随机的函数是什么? [英] What is the most random function in C++?

查看:93
本文介绍了C ++中最随机的函数是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用了

 #include< stdlib> 
#include< time>
using namespace std;
srand((unsigned)time(0));
int n =(rand()>> 8)%4;

但是还有什么其他随机函数,或者什么其他函数可以用作随机数生成器? / p>

编辑:我真的没有特别的理由提出这个问题,我只想知道C ++是否有任何其他随机函数。

$ b $ rand()和srand()函数都是C ++标准指定的。如果要写自己的,请注意约翰·冯·诺伊曼说:


任何人认为算术
方法生成随机数字是
当然是在罪状



I've used

#include<stdlib>
#include<time>
using namespace std;
srand((unsigned)time(0));
int n=(rand()>>8)%4;

but what other random functions are there, or what other function could be used as random number generators?

EDIT: I don't really have a particular reason for asking this question, I just wanted to know if C++ had any other random functions.

解决方案

The rand() and srand() functions are all the C++ Standard specifies. And if it comes to writing your own, be aware of what John von Neumann said:

"Anyone who considers arithmetical methods of producing random digits is of course in a state of sin"

这篇关于C ++中最随机的函数是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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