Skip to content

Instantly share code, notes, and snippets.

@dakait
Created August 29, 2018 11:44
Show Gist options
  • Save dakait/d4fc7194a5eb7213dec39113ce32c0b6 to your computer and use it in GitHub Desktop.
Save dakait/d4fc7194a5eb7213dec39113ce32c0b6 to your computer and use it in GitHub Desktop.
Generate random code golang
import "crypto/rand"
func generateRandomSecret(size int) string {
alphanum := "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefbgijklmnopqrstuvwxyz0123456789"
var bytes = make([]byte, size)
rand.Read(bytes)
for i, b := range bytes {
bytes[i] = alphanum[b%byte(len(alphanum))]
}
return string(bytes)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment