Created
January 28, 2023 23:28
-
-
Save sokol8/af053c4971644323b34b75feaccbf402 to your computer and use it in GitHub Desktop.
Radnom string generation
This file contains 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
// based on https://gist.github.com/szhernovoy/276e69eb90a0de84dd90 | |
// and my performance measurements | |
public func randomString(of length: Int) -> String { | |
let letters = Array("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789") | |
var s = "" | |
for _ in 0 ..< length { | |
s.append(letters.randomElement()!) | |
} | |
return s | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment