How can I get a floating point number to be random between two digits and for that to be 4 decimal places. Example
Between the two digits between 0-1 and a random 4 decimal place number between them would be 0.0008f.
How can I get a floating point number to be random between two digits and for that to be 4 decimal places. Example
Between the two digits between 0-1 and a random 4 decimal place number between them would be 0.0008f.
As @NathanOliver explained, there is a lot of info out there. I recommend to do some research.
An easy solution would be to get a random between [1-10[K and then divide the value by 10K.
You can use integers all the time if you do not need the division. Depends what you want to do with your code.
Generate a random number between 1 and 9999 (both inclusive). Then divide that number by 10000 and you have the result you want.
And please use the facilities in <random>
rather than srand()/rand()
. The latter produces horrible quality random numbers.