随机数的生成

2017-08-20  17:43:29

writer:pprp

我们采用随机数可以对我们的算法进行大数据检验

/*
name : 简单的随机数生成算法
writer : pprp
declare : null
date ; 2017/8/20
*/
#include <bits/stdc++.h>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <vector>

using namespace std;
const int maxn = 100;
int a[maxn];

int main()
{
      //每次执行的种子不同,生成的随机数才不相同
      srand((int)time(NULL));
      //产生10个随机数,记录在vector中,其中随机数的范围是0到100
      for(int i = 0 ; i < 10 ; i++)
      {
           a[i] = rand() % 100; 
      }
      
      for(int i = 0 ; i < 10 ; i++)
      {
            cout <<a[i] <<" ";
      }
      cout << endl;
      return 0;
}
原文地址:https://www.cnblogs.com/pprp/p/7401072.html