How can I generate a random alphanumeric string in Swift?
In the unusual case that
Here is an extremely clear function that caches:
func randomNameString(length: Int = 7)->String{
enum s {
static let c = Array("abcdefghjklmnpqrstuvwxyz12345789")
static let k = UInt32(c.count)
}
var result = [Character](repeating: "-", count: length)
for i in 0..
This is for when you have a fixed, known character set.
Handy tip:
There is no 0, o, O, i, etc ... the characters humans often confuse.
This is often done for booking codes and similar codes which human customers will use.