我想在Swift中生成多个不同的随机数。以下是操作步骤。
- Set up an empty array
- Generate a random number
Check if the array is empty
a. If the array is empty, insert the random number
b. If the array is not empty, compare the random number to the numbers in array
i. If the numbers are the same, repeat 2
ii. if the numbers are not the same, insert the random number and repeat 2import UIKit //the random number generator func randomInt(min: Int, max:Int) -> Int { return min + Int(arc4random_uniform(UInt32(max - min + 1))) } var temp = [Int]() for var i = 0; i<4; i++ { var randomNumber = randomInt(1, 5) if temp.isEmpty{ temp.append(randomNumber) } else { //I don't know how to continue... } }