Skip to content

Instantly share code, notes, and snippets.

@RuNpiXelruN
Created May 22, 2020 10:57
Show Gist options
  • Save RuNpiXelruN/f2a499b0dd9049f5c7728e6e8a01fa8b to your computer and use it in GitHub Desktop.
Save RuNpiXelruN/f2a499b0dd9049f5c7728e6e8a01fa8b to your computer and use it in GitHub Desktop.
Create a random string in Go
func randStr(len int) string {
buff := make([]byte, len)
rand.Read(buff)
str := base64.StdEncoding.EncodeToString(buff)
// Base 64 can be longer than len
return strings.ToLower(str[:len])
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment