Swift - Use arc4random(), arc4random_uniform() to get random numbers

 

The arc4random()  global function generates 10-digit random integers (UInt32). The maximum value it generates is 4294967295 (2^32 - 1) and the minimum value is 0.
 

1. The following is to use the  arc4random  function to find a  random number from 1 to 100  (including 1 and 100)

1
let temp = Int(arc4random()% 100 )+ 1


2. The following is to use the  arc4random_uniform  function to find a  random number from 1 to 100  (including 1 and 100)

1
let temp = Int(arc4random_uniform( 100 ))+ 1


The original text comes from: www.hangge.com  

Original link: http://www.hangge.com/blog/cache/detail_512.html

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326177879&siteId=291194637