// This program seeds the random-number generator
// with the time, then displays 10 random integers.
//
#include <iostream>
//#include <cstdlib>
//#include <cstdio>
#include <ctime>
using namespace std;
int Random(int MIN, int MAX);
// generate a random number
int main()
{
// set the random-number seed with the current time
srand((unsigned)time(NULL));
cout << "请输入要产生的随机数的个数:";
int NUM;
cin >> NUM;
cout << "现在开始产生随机数..." << endl;
int min, max;
cout << "请输入要产生的随机数的下限:";
cin >> min;
cout << "请输入要产生的随机数的上限:";
cin >> max;
//generate the random numbers
int randoms;
for (int i=0; i<NUM; i++)
{
randoms = Random(min,max);
cout << randoms << "
";
}
cout << endl;
system("pause");
return 0;
}
int Random(int MIN, int MAX)
{
return (((double)rand() / (double)RAND_MAX)*MAX + MIN);
}
我前不久也遇到了同样的问题.
我用的就是上面的代码.不知道合不合你的要求.