随机数生成(swift)
by 伍雪颖
override
func
viewDidLoad() {
super . viewDidLoad ()
for _ in 0 ... 100 {
println ( randomInRange ( 1 ... 6 ))
}
}
func randomInRange(range: Range < Int >) -> Int {
let count = UInt32 (range. endIndex - range. startIndex )
return Int ( arc4random_uniform (count)) + range. startIndex
super . viewDidLoad ()
for _ in 0 ... 100 {
println ( randomInRange ( 1 ... 6 ))
}
}
func randomInRange(range: Range < Int >) -> Int {
let count = UInt32 (range. endIndex - range. startIndex )
return Int ( arc4random_uniform (count)) + range. startIndex
}
原文链接:https://www.f2er.com/swift/326740.html