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())
}

["H", "B", "G", "C", "F", "E", "D", "A"]
["E", "B", "G", "H", "C", "A", "F", "D"]


댓글

이 블로그의 인기 게시물

지금 이 순간