Created
November 10, 2021 18:55
-
-
Save apple-avadhesh/90abe57a9dba97dfadd5b45b01d9acfd to your computer and use it in GitHub Desktop.
GenerateRandomStringFromArray
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 generateRandom(length: Int) -> String { | |
let letters = ["q", "w", "e", "r", "t", "y", "u", "i", "o", "p", "a", "s", "d", "f", "g", "h", "j", | |
"k", "l", "z", "x", "c", "v", "b", "n", "m"] | |
var str = "" | |
for _ in 0 ..< length { | |
str.append(letters.randomElement()!) | |
} | |
return str | |
} | |
let we = generateRandom(length: 10) | |
print(we) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment