Instance MethodSwift
shuffle()
Shuffles the collection in place.
Available because
Self
conforms toMutableCollection
.Available when
Self
conforms toRandomAccessCollection
mutating func shuffle()
Overview
Use the shuffle()
method to randomly reorder the elements of an array.
var names = ["Alejandro", "Camila", "Diego", "Luciana", "Luis", "Sofía"]
names.shuffle()
// names == ["Luis", "Camila", "Luciana", "Sofía", "Alejandro", "Diego"]
This method is equivalent to calling shuffle(using:)
, passing in the system’s default random generator.