Swift - 使用arc4random()、arc4random_uniform()取得随机数

in #cn7 years ago (edited)

swift

Arc4random() , the global function generates a 10-digit random integer (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)
    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)
    let temp = Int(arc4random_uniform(100))+1

Next, the interval operator will be updated.(... and ..<)



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

接下来会更新区间运算符(... and ..<)

Sort:  

Hello @kingliu! This is a friendly reminder that you have 3000 Partiko Points unclaimed in your Partiko account!

Partiko is a fast and beautiful mobile app for Steem, and it’s the most popular Steem mobile app out there! Download Partiko using the link below and login using SteemConnect to claim your 3000 Partiko points! You can easily convert them into Steem token!

https://partiko.app/referral/partiko

Congratulations @kingliu! You received a personal award!

Happy Birthday! - You are on the Steem blockchain for 1 year!

You can view your badges on your Steem Board and compare to others on the Steem Ranking

Vote for @Steemitboard as a witness to get one more award and increased upvotes!

Coin Marketplace

STEEM 0.04
TRX 0.33
JST 0.078
BTC 62741.70
ETH 1659.93
USDT 1.00
SBD 0.42