shuffled
func shuffleTest() {
var items = ["A", "B", "C", "D", "E", "F", "G", "H"]
let copyItems = items
var shuffled = [String]()
for i in 0..<items.count {
let rand = Int(arc4random_uniform(UInt32(items.count)))
shuffled.append(items[rand])
items.remove(at: rand)
}
print(shuffled)
print(copyItems.shuffled())
}
var items = ["A", "B", "C", "D", "E", "F", "G", "H"]
let copyItems = items
var shuffled = [String]()
for i in 0..<items.count {
let rand = Int(arc4random_uniform(UInt32(items.count)))
shuffled.append(items[rand])
items.remove(at: rand)
}
print(shuffled)
print(copyItems.shuffled())
}
["H", "B", "G", "C", "F", "E", "D", "A"]
["E", "B", "G", "H", "C", "A", "F", "D"]
댓글
댓글 쓰기