题目:有5个数,假设是1到5,每次抽到的概率相等,每次抽到后都放回,编程实现
#include<iostream>
#include<stdlib.h>
#include <ctime>
#include <cstdlib>
using namespace std;
int main()
{
srand( (unsigned)time( NULL ) );
//srand(unsigned(time(0))); 这是原来的随机数产生语句,用上一行的替换了
int a[5] = {1,2,3,4,5};
int i = 1;
while(i<=10)
{
int b=rand()%5;
cout<< a[b] <<endl;
i++;
}
cin>>i;
return 0;
}