使用此代码arc4random使得出现0到3之间的随机数,但它通常会在一行中显示相同的数字,那么,我如何使arc4random在一行中不显示相同的数字? (例如:1-3不是1-1或2-2)
func setRandomPosition() {
let i = arc4random_uniform(4)
createRandomXY()
if i == 0 {
self.rect.center.x = self.topXRandomPosition
self.rect.center.y = self.topYRandomPosition
} else if i == 1 {
self.rect.center.x = self.bottomXRandomPosition
self.rect.center.y = self.bottomYRandomPosition
} else if i == 2 {
self.rect.center.x = self.rightXRandomPosition
self.rect.center.y = self.rightYRandomPosition
} else if i == 3 {
self.rect.center.x = self.leftXRandomPosition
self.rect.center.y = self.leftYRandomPosition
}
}