Last active
September 18, 2024 15:08
-
-
Save koonix/08f912cc7470d4097f850bccbe3129f7 to your computer and use it in GitHub Desktop.
Go random byte generator
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
func RandomBytes(length int) []byte { | |
const charset = "abcdefghijklmnopqrstuvwxyz" + | |
"ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789\t\n " | |
b := make([]byte, length) | |
for i := range b { | |
b[i] = charset[rand.Intn(len(charset))] | |
} | |
return b | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment