Last active
June 1, 2016 11:32
-
-
Save werner-freytag/efc9064cda8e947cd32b643bb3e4e467 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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