我开发了一些代码来生成五个数组,每个数组包含1到49之间的六个数字。我使用arc4random_uniform(49)
函数来尝试这样做。但是,当appendArrays()
为所有五个循环生成相同的数字集时。
class six49: lottery {
var price: Int
var winner: [Int] = []
override init(draws: Int, lines: Int){
price = 3
super.init(draws: draws, lines: lines)
}
func appendArrays(win: inout [Int], win2: inout [[Int]]) -> [[Int]] {
while win2.count < lines {
while win.count < 6 {
let selection = arc4random_uniform(49)
if win.contains(Int(selection)){
continue
} else {
win.append(Int(selection))
win = win.sorted()
}
}
win2.append(win)
}
return win2
}
}
let result = six49(draws: 1, lines: 5)
var arr2: [[Int]] = []
var arr1: [Int] = []
var collection = result.appendArrays(win: &arr1,win2: &arr2)
print(collection)
这是输出:
<[,[11,16,27,31,37,39],[11,16,27,31,37,39],[11,16,27,31,37,39],[11,16] ,27,31,37,39],[11,16,27,31,37,39]]
我一直在寻找每个循环尝试创建不同的数字集,但我似乎无法找到任何解决方案。