Skip to content

Instantly share code, notes, and snippets.

@se77en
Last active August 29, 2015 13:57
Show Gist options
  • Save se77en/9403380 to your computer and use it in GitHub Desktop.
Save se77en/9403380 to your computer and use it in GitHub Desktop.
random string in Go
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