How do I randomize or shuffle the elements within an array in Swift? For example, if my array consists of 52 playing cards, I want to shuffle the array in o
As of swift 4.2 there are two handy functions:
// shuffles the array in place myArray.shuffle()
and
// generates a new array with shuffled elements of the old array let newArray = myArray.shuffled()