Skip to content

Instantly share code, notes, and snippets.

@sebastienwindal
Created July 30, 2017 05:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sebastienwindal/a0caf7a6f43d0784e4a181638438e83f to your computer and use it in GitHub Desktop.
Save sebastienwindal/a0caf7a6f43d0784e4a181638438e83f to your computer and use it in GitHub Desktop.
// 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