I give it 0 and 400 and it returns me sometimes values above 400. That doesn’t make sense.
- (float)randomValueBetween:(float)low andValue:(float)high {
return (((float) arc4random() / RAND_MAX) * (high - low)) + low;
}
that’s actually a snippet I found on the net. Maybe someone can see the bug in there?
The manual page for
arc4randomindicates that the returned value can be anywhere in the range valid foru int32(i.e.0 to (2**32)-1). This means you’ll want to divide by0xFFFFFFFF, instead ofRAND_MAX, which I would imagine is less (it is library dependant however, so you’ll have to check exactly what it is).Your function should thus become: