Last active
August 29, 2015 13:57
-
-
Save se77en/9403380 to your computer and use it in GitHub Desktop.
random string in Go
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 randomString(size int) string { | |
alpha = `abcdefghijkmnpqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ23456789` //better to define a const | |
buf := make([]byte, size) | |
for i := 0; i < size; i++ { | |
buf[i] = alpha[rand.Intn(len(alpha))] | |
} | |
return string(buf) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment