产生0到100之间的随机数

经常用到的东西,写在这里做个记录.

#include "stdafx.h"
#include "stdlib.h"
#include <iostream>
#include <time.h>
#include <vector>

using namespace std;

int _tmain(int argc,_TCHAR* argv[])
{
  srand((unsigned)time(NULL));
  int high=100,low=0;
  vector<int> date;
  for(int i=0;i<10;i++)
   {
     date.push_back(rand()%(high-low+1)+low);

   }
  vector<int>::iterator iter=date.begin();
  for(;iter!=date.end();iter++)  //注意此处end()和back的区别,end()指向末位元素的下一个位置,而back()才是指向的末位元素
  {
    cout<<*iter<<endl;
  }
system("pause");
return 0;
}

猜你喜欢

转载自blog.csdn.net/l93919861/article/details/84647346