I'm trying to generate a random number that's between 0 and 1. I keep reading about arc4random()
, but there isn't any information about getting a float from it. How do I do this?
Generate a random float number between 0 to 1Use a random. random() function of a random module to generate a random float number uniformly in the semi-open range [0.0, 1.0) . Note: A random() function can only provide float numbers between 0.1. to 1.0.
The Random random() method generates the number between 0.0 and 1.0.
Random value in [0, 1[ (including 0, excluding 1):
double val = ((double)arc4random() / UINT32_MAX);
A bit more details here.
Actual range is [0, 0.999999999767169356], as upper bound is (double)0xFFFFFFFF / 0x100000000.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With