我一直在試圖運行這個循環來改變陣列中元素的位置,但是我得到下面的錯誤。不太確定會出現什麼問題。任何想法或想法!謝謝。替換陣列中元素的位置
var population = [[98, 8, 45, 34, 56], [9, 13, 65, 4, 90], [24, 5, 4, 56, 88], [3, 55, 22, 19, 10]]
private func randomIntergerInRange(low:Int, high:Int) -> Int {
let randomGeneratedNumber = low + Int(arc4random()) % (high - low);
return Int(randomGeneratedNumber)
}
for individual in population {
var mutate = 0.01
if mutate > Double(Float(arc4random())/Float(UINT32_MAX)) {
var positionToMutate = randomIntergerInRange(0, (individual.count - 1))
var valueToAssign = randomIntergerInRange(minElement(individual), maxElement(individual))
individual[positionToMutate] = valueToAssign
print(individual)
}
}
爲什麼你的陣列看起來更像是一個字典 – Lamar
這是陣列@Lamar陣列;) – Gugulethu