Created
August 29, 2018 11:44
-
-
Save dakait/d4fc7194a5eb7213dec39113ce32c0b6 to your computer and use it in GitHub Desktop.
Generate random code golang
This file contains 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
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