Skip to content

Instantly share code, notes, and snippets.

@DavadDi
Created May 28, 2017 02:36
Show Gist options
  • Save DavadDi/8944292b59d7e74812cb91788218a246 to your computer and use it in GitHub Desktop.
Save DavadDi/8944292b59d7e74812cb91788218a246 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