Created
January 20, 2019 19:11
-
-
Save shishirthedev/bde30dc97741d55dfcfecca88411d099 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
func randomString(length: Int) -> String { | |
let letters : NSString = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" | |
let len = UInt32(letters.length) | |
var randomString = "" | |
for _ in 0 ..< length { | |
let rand = arc4random_uniform(len) | |
var nextChar = letters.character(at: Int(rand)) | |
randomString += NSString(characters: &nextChar, length: 1) as String | |
} | |
return randomString | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment