Skip to content

Instantly share code, notes, and snippets.

@henvic
Created Oct 2, 2020
Embed
What would you like to do?
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