Skip to content

Instantly share code, notes, and snippets.

@sboc
sboc / gist:ceae6b184527cf88bf5d
Created August 29, 2014 08:22
Shuffle an array in Apple's Swift
extension Array {
mutating func shuffle() {
var temp = self
self.removeAll(keepCapacity: true)
while (temp.isEmpty == false) {
var index = Int(arc4random() % UInt32(temp.count))
self.append(temp.removeAtIndex(index))
}
}
}