Skip to content

Instantly share code, notes, and snippets.

@gkye
Last active February 22, 2016 03:59
Show Gist options
  • Save gkye/c5b2d78d21f0146d33f1 to your computer and use it in GitHub Desktop.
Save gkye/c5b2d78d21f0146d33f1 to your computer and use it in GitHub Desktop.
shuffle array (self)
mutating func shuffle() {
if count < 2 { return }
for i in 0..<(count - 1) {
let j = Int(arc4random_uniform(UInt32(count - i))) + i
swap(&self[i], &self[j])
}
}
var tags = [1,7782,25]
tags.shuffle()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment