Skip to content

Instantly share code, notes, and snippets.

@henvic
Created October 2, 2020 13:57
Show Gist options
  • Save henvic/7473d7cc77031f53277e16e2609348bd to your computer and use it in GitHub Desktop.
Save henvic/7473d7cc77031f53277e16e2609348bd to your computer and use it in GitHub Desktop.
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