Created
March 19, 2015 02:52
-
-
Save markawil/b1b9d3da47e9a5c515b0 to your computer and use it in GitHub Desktop.
Swift shuffle array
This file contains hidden or 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
var myArray = [1,2,3,4,5,6,7,8] | |
func shuffleArray(array: [Int]) -> [Int] { | |
var tempArray = array | |
for index in 0...array.count - 1 { | |
let randomNumber = arc4random_uniform(UInt32(myArray.count - 1)) | |
let randomIndex = Int(randomNumber) | |
tempArray[randomIndex] = array[index] | |
} | |
return tempArray | |
} | |
shuffleArray(myArray) | |
shuffleArray(myArray) | |
shuffleArray(myArray) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment