package tools import ( "math/rand" "time" ) func init() { // 随机数种子 rand.Seed(time.Now().UnixNano()) } // RandStr 生成随机数 func RandStr(n int, str ...string) string { s := "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890" if len(str) > 0 { s = str[0] } res := "" for i := 0; i < n; i++ { res += string(s[rand.Intn(len(s))]) } return res }