In C language , the rand function returns an integer. How to generate a random floating point number?
We can use division to get decimals and random floating point numbers from 0 to 1.
Then multiply by X to get a floating point number from 0 to X:
float f = (float)rand()/(float)(RAND_MAX/X);