Note:Here’s how the above method works.arc4random()
gives you a randominteger between 0 andARC4RANDOM_MAX. If you divide that
number byARC4RANDOM_MAX, you get a float between 0 and 1.
If you multiply this value by the range of values (max–
min), you’ll get a floatbetween 0 and the range. If you add to that themin
value, you’ll get a floatbetweenmin
andmax. Viola?, job done!
时间: 2024-12-21 11:49:14