Skip to content

Instantly share code, notes, and snippets.

@Subi
Last active April 4, 2020 23:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Subi/c684d4b684cb5e21f2e8fc3642daae04 to your computer and use it in GitHub Desktop.
Save Subi/c684d4b684cb5e21f2e8fc3642daae04 to your computer and use it in GitHub Desktop.
Generate a random size string nonce.
func genNonce(length int) string {
const charset = "abcdefghijklmnopqrstuvwxyz" +
"ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
nonce := ""
for i := 0; i < length; i++ {
rand.Seed(time.Now().UnixNano())
nonce += strings.Split(charset, "")[rand.Intn(len(strings.Split(charset, "")))]
}
return strings.ToUpper(nonce)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment