Last active
December 2, 2018 00:48
-
-
Save JacopoMangiavacchi/c49154b4c22d4e8dcfe32cddc87ee832 to your computer and use it in GitHub Desktop.
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
import Foundation | |
extension Array { | |
mutating func randomize() { | |
for i in 0..<self.count { | |
let r = Int.random(in: 0..<Int(self.count - i)) | |
(self[i], self[i+r]) = (self[i+r], self[i]) | |
} | |
} | |
} | |
var intArray:[Int] = (0..<99).map{$0} | |
var stringArray:[String] = (0..<25).map{String(Character(UnicodeScalar(Int(("A" as UnicodeScalar).value) + $0)!))} | |
var stringArray2:[String] = "jmangia".map{String($0)} | |
print(intArray) | |
print(stringArray) | |
print(stringArray2) | |
intArray.randomize() | |
stringArray.randomize() | |
stringArray2.randomize() | |
print(intArray) | |
print(stringArray) | |
print(stringArray2) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment