首页 > 编程语言 > 详细

使用C++ 11自带的库函数生成随机数

时间:2015-09-10 15:44:14      阅读:202      评论:0      收藏:0      [点我收藏+]
#include <random>
#include <iostream>
using namespace std;

void random_number() {
    default_random_engine g;
    uniform_int_distribution<int> rand(0,9);
    for (int i=0; i<10; i++) cout << rand(g) << " ";
    cout << endl;
    uniform_real_distribution<float> uniform(0,1);
    for (int i=0; i<10; i++) cout << uniform(g) << " ";
    cout << endl;
}

int main() {
    random_number();
    return 0;
}

  

需要C++ 11 支持。

使用C++ 11自带的库函数生成随机数

原文:http://www.cnblogs.com/marginalman/p/4797867.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!