random number generator in C++# Programming - 葵花宝典
a*n
1 楼
i want to generate 100 random numbers between 0-1,
why the following program only generate 100 SAME numbers?
#include
#include
float random(int lowest, int highest)
//return a random number between highest and lowest
{
srand(time(NULL));
float result=0.0;
int range=(highest-lowest)+1;
if(highest<=lowest)
return 0.0;
else {
result = float(lowest)+range*rand()/(RAND_MAX + 1.0);
return result;
}
why the following program only generate 100 SAME numbers?
#include
#include
float random(int lowest, int highest)
//return a random number between highest and lowest
{
srand(time(NULL));
float result=0.0;
int range=(highest-lowest)+1;
if(highest<=lowest)
return 0.0;
else {
result = float(lowest)+range*rand()/(RAND_MAX + 1.0);
return result;
}