random(new)_C/C++_编程开发_程序员俱乐部

中国优秀的程序员网站程序员频道CXYCLUB技术地图
热搜:
更多>>
 
您所在的位置: 程序员俱乐部 > 编程开发 > C/C++ > random(new)

random(new)

 2013/7/21 15:02:47  xiangjie88  程序员俱乐部  我要评论(0)
  • 摘要:#include<iostream>#include<random>usingnamespacestd;/*default_random_engineneedtobestatic*/vector<int>errorRandomFun(){default_random_enginee;//generatorrandomnumin0-14uniform_int_distribution<unsigned>u(0,15);vector<
  • 标签:
class="c++" name="code">
#include<iostream>
#include<random>
using namespace std;

/*
    default_random_engine need to be static
*/
vector<int> errorRandomFun()
{
    default_random_engine e;
    //generator random num in 0-14
    uniform_int_distribution<unsigned> u(0,15);
    vector<int> vec;
    for(int i=0;i<5;i++)
    {
        int num = u(e);
        vec.push_back(num);
        cout << num << " ";
    }
    cout << endl;

    return vec;
}

vector<int> randomFun()
{
    static default_random_engine e;
    //generator random num in 0-14
    uniform_int_distribution<unsigned> u(0,15);
    vector<int> vec;
    for(int i=0;i<5;i++)
    {
        int num = u(e);
        vec.push_back(num);
        cout << num << " ";
    }
    cout << endl;

    return vec;
}

int main()
{
    default_random_engine e;
    cout << "min:" << e.min() << ",max:" << e.max() << endl;
    for(int i=0;i<5;i++){
        cout << e() << " ";
    }
    cout << endl;

    cout << "error random function:" << endl;
    errorRandomFun();
    errorRandomFun();

    cout << "right random function:" << endl;
    randomFun();
    randomFun();
}

min:1,max:2147483646
16807 282475249 1622650073 984943658 1144108930 
error random function:
0 2 12 7 8 
0 2 12 7 8 
right random function:
0 2 12 7 8 
3 0 10 10 14 
上一篇: C++图形边缘检测与区域提取 下一篇: 没有下一篇了!
  • 相关文章
发表评论
用户名: 匿名