iOS生成最大最小數之間隨機數

躍然發表於2014-11-03

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 (maxmin), you’ll get a floatbetween 0 and the range. If you add to that themin value, you’ll get a floatbetweenmin andmax. Violà, job done! 


相關文章