美文网首页
Swift - 使用arc4random()、arc4rando

Swift - 使用arc4random()、arc4rando

作者: 乖_摸摸头F | 来源:发表于2018-11-16 14:17 被阅读0次
arc4random() 这个全局函数会生成10位数的随机整数(UInt32)。其生成的最大值是4294967295(2^32 - 1),最小值为0。
1、使用 arc4random 函数求一个 1~100 的随机数(包括1和100)

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

2、使用 arc4random_uniform 函数求一个 1~100 的随机数(包括1和100)

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

相关文章

网友评论

      本文标题:Swift - 使用arc4random()、arc4rando

      本文链接:https://www.haomeiwen.com/subject/ywlmfqtx.html