Swift - 使用arc4random()、arc4random_uniform()取得随机数
arc4random()这个全局函数会生成9位数的随机整数
1,下面是使用arc4random函数求一个1~100的随机数(包括1和100)
|
1
|
var temp:Int = Int(arc4random()%100)+1 |
2,下面是使用arc4random_uniform函数求一个1~100的随机数(包括1和100)
|
1
|
var temp:Int = Int(arc4random_uniform(100))+1 |

浙公网安备 33010602011771号