How to shuffle elements in an array in Swift
arrays
language
tips
If you have an array or a sequence of elements that you want to arrange in a random order then
you can use a built in function that Swift provides, called shuffled()
.
Let’s consider that you have an array of Integers
In the above example, the sequence is random, so executing this again can result in a different sequence each time.
Sponsored