Skip to content

Instantly share code, notes, and snippets.

@sokol8
Created January 28, 2023 23:28
Show Gist options
  • Save sokol8/af053c4971644323b34b75feaccbf402 to your computer and use it in GitHub Desktop.
Save sokol8/af053c4971644323b34b75feaccbf402 to your computer and use it in GitHub Desktop.
Radnom string generation
// 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