Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save werner-freytag/efc9064cda8e947cd32b643bb3e4e467 to your computer and use it in GitHub Desktop.
Save werner-freytag/efc9064cda8e947cd32b643bb3e4e467 to your computer and use it in GitHub Desktop.
extension Array {
var shuffled:[Element] {
var clone = self
for index1 in 0..<count {
let index2 = Int(arc4random_uniform(UInt32(count)))
guard index1 != index2 else { continue }
swap( &clone[index1], &clone[index2] )
}
return clone
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment