float genData(int low, int high);
int main(){
srand(time(0));
float num = genData(40, 100);
cout << fixed << left << setprecision(2) << num << endl;
return 0;
}
float genData(int low, int high) {
low *= 100;
high *= 100 + 1;
int rnd = rand() % (high - low) + low;
float newRand;
newRand = (float) rnd / 100;
return newRand;
}
I'm expecting a random number between 40 and 100 inclusively with two decimal places. eg: 69.69, 42.00
What I get is the same number with different decimal values, slowly increasing every time I run the program.