Instance Method


Shuffles the collection in place.


mutating func shuffle()


Use the shuffle() method to randomly reorder the elements of an array.

var names = ["Alejandro", "Camila", "Diego", "Luciana", "Luis", "Sofía"]
names.shuffle(using: myGenerator)
// names == ["Luis", "Camila", "Luciana", "Sofía", "Alejandro", "Diego"]

This method is equivalent to calling shuffle(using:), passing in the system’s default random generator.

Complexity: O(n), where n is the length of the collection.

Beta Software

This documentation contains preliminary information about an API or technology in development. This information is subject to change, and software implemented according to this documentation should be tested with final operating system software.

Learn more about using Apple's beta software