Skip to content

Instantly share code, notes, and snippets.

@warriorg
Forked from DavadDi/go_rand_str.go
Created June 30, 2017 05:38
Show Gist options
  • Save warriorg/5a6aaf5be933686fb1468c7cf4eddde5 to your computer and use it in GitHub Desktop.
Save warriorg/5a6aaf5be933686fb1468c7cf4eddde5 to your computer and use it in GitHub Desktop.
var (
codes = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/~!@#$%^&*()_="
codeLen = len(codes)
)
func RandNewStr(len int) string {
data := make([]byte, len)
rand.Seed(time.Now().UnixNano())
for i := 0; i < len; i++ {
idx := rand.Intn(codeLen)
data[i] = byte(codes[idx])
}
return string(data)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment