标签:
//产生区间[a,b]内的随机数(整数)
#include<iostream>
#include <ctime>
using namespace std;
void main()
{
int a,b,c;
srand((double)time(NULL));
cout<<"please input the range: ";
cin>>a>>b;
for(int i=0;i<5;i++)
{
c=a+rand()%(b-a+1);
cout<<c<<" ";
}
system("pause");
}
//生成随机的小数
#include<iostream>
#include <ctime>
using namespace std;
void main()
{
srand((unsigned int)time(NULL));
for(int i=0;i<10;i++)
{
cout<<(float)rand()/RAND_MAX<<endl;
}
system("pause");
return;
}
标签:
原文地址:http://www.cnblogs.com/runningRain/p/5838093.html