I currently have a method to attempt to get a random float between two numbers that I provide however, it does not work properly.
For example if I feed in 4.0 as the lower float and 4.5 as the higher float, I get results that are like 0.8 or 1.2 and sometimes it is between those two numbers. So this leads me to believe that this method is no good. Here is the method:
- (float)randomFloatBetween:(float)num1 andLargerFloat:(float)num2 {
return ((float)arc4random() / ARC4RANDOM_MAX) * num2-num1 + num1;
}
This is ARC4RANDOM_MAX
#define ARC4RANDOM_MAX 0x100000000
Anyway, what is causing this and how can I fix this?
Thanks!
Your code means this:
You need parentheses around
num2-num1: