Skip to content

Instantly share code, notes, and snippets.

@diwakergupta
Created October 12, 2015 22:24
Show Gist options
  • Save diwakergupta/fa17945dd70c68938a5e to your computer and use it in GitHub Desktop.
Save diwakergupta/fa17945dd70c68938a5e to your computer and use it in GitHub Desktop.
func GenerateRandomString(length int) string {
const chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890abcdefghijklmnopqrstuvwxyz"
rand.Seed(time.Now().Unix())
str := make([]string, length)
for i := 0; i < length; i++ {
index := rand.Intn(len(chars))
str[i] = chars[index : index+1]
}
return strings.Join(str, "")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment