Created
October 2, 2020 13:57
-
-
Save henvic/7473d7cc77031f53277e16e2609348bd to your computer and use it in GitHub Desktop.
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
func new11RandomID() string { | |
const ( | |
alphabet = "123456789ABCDEFGHJKLMNPQRSTUWVXYZabcdefghijkmnopqrstuwvxyz" // base58 | |
size = 11 | |
) | |
var id = make([]byte, size) | |
if _, err := rand.Read(id); err != nil { | |
panic(err) | |
} | |
for i, p := range id { | |
id[i] = alphabet[int(p)%len(alphabet)] // discard everything but the least significant bits | |
} | |
return string(id) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment