随机数生成(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
}