Last active
August 29, 2015 14:27
-
-
Save isoiphone/0f7da6626629a9c634dd to your computer and use it in GitHub Desktop.
Swift 2.0 strings-- I don't understand
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
| private let ValidCharacters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789\n".utf8 | |
| private func RandomString() -> String { | |
| var str = "" | |
| // 1-140 | |
| let len = 1+(Int(rand())%140) | |
| for _ in 0...len { | |
| let offset = Int(rand())%Int(ValidCharacters.count) | |
| let index = advance(ValidCharacters.startIndex, offset) | |
| let ch = UnicodeScalar(UInt8(ValidCharacters[index].value)) | |
| str.append(ch) | |
| } | |
| return str | |
| } |
jtbandes
commented
Aug 9, 2015
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment