Notice: 函数 WP_Scripts::localize 的调用方法不正确$l10n 参数必须是一个数组。若要将任意数据传递给脚本,请改用 wp_add_inline_script() 函数。 请查阅调试 WordPress来获取更多信息。 (这个消息是在 5.7.0 版本添加的。) in /data/www/appblog/wp-includes/functions.php on line 6131

Swift – 使用arc4random()、arc4random_uniform()获取随机数

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 - 基本数据类型,常量及变量声明
下一篇 Swift - 区间运算符