【发布时间】:2015-08-05 14:07:03
【问题描述】:
我的代码仅随机移除一枚硬币。如何随机取出 1 到 3 个硬币?
@IBAction func endTurn(sender: UIButton!) {
if coins.count > 0 { // @IBOutlet var coins: [UIButton]! (21 coins)
let index: Int = Int(arc4random_uniform(UInt32(coins.count)))
coins[index].hidden = true
self.coins.removeAtIndex(index)
if coins.isEmpty {
println("GameOver")
}
}
}
【问题讨论】:
-
在 1 和 3 之间做一个随机数和一个 for 循环调用你的代码?
-
已经在这里回答 stackoverflow.com/questions/5601953/… 注意:使用 arc4random 而不是 rand
标签: swift random hidden arc4random