Last active
April 4, 2020 23:18
-
-
Save Subi/c684d4b684cb5e21f2e8fc3642daae04 to your computer and use it in GitHub Desktop.
Generate a random size string nonce.
This file contains hidden or 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 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