Created
July 30, 2017 05:25
-
-
Save sebastienwindal/a0caf7a6f43d0784e4a181638438e83f 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
// Fisher–Yates Array shuffle | |
extension Array { | |
func shuffledArray() -> Array { | |
var arr = self | |
for i in 0..<count { | |
print(count - i) | |
let j = i + Int(arc4random_uniform(UInt32(count - i))) | |
let tmp = arr[i] | |
arr[i] = arr[j] | |
arr[j] = tmp | |
} | |
return arr | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment