怎样用C++发生16bit的随机数并存入到vector函数中呢
怎样用C++产生16bit的随机数并存入到vector函数中呢
怎样用C++产生16bit的随机数并存入到vector函数中呢
------解决方案--------------------
你是不了解如何生成随机数,还是不了解如何使用std::vector?
------解决方案--------------------
这个没用srand,所以每次的随机数都同:
怎样用C++产生16bit的随机数并存入到vector函数中呢
------解决方案--------------------
你是不了解如何生成随机数,还是不了解如何使用std::vector?
------解决方案--------------------
这个没用srand,所以每次的随机数都同:
#include<stdio.h>
#include<stdlib.h>
#include <vector>
using namespace std;
#define random(x) (rand()%x)
int main()
{
vector<int> vec;
for(int x=0;x<10;x++)
vec.push_back(random(100));
int i=0;
for(vector<int>::iterator iter=vec.begin();
iter!=vec.end();++iter)
printf("vec[%d]:0X%02X \n",++i,*iter);
return 0;
}
/*
输出:
vec[1]:0X29
vec[2]:0X43
vec[3]:0X22
vec[4]:0X00
vec[5]:0X45
vec[6]:0X18
vec[7]:0X4E
vec[8]:0X3A
vec[9]:0X3E
vec[10]:0X40
请按任意键继续. . .
*/