package utils import ( crand "crypto/rand" "fmt" "github.com/syyongx/php2go" "math" "math/big" "math/rand" "time" ) func RandString(l int, c ...string) string { var ( chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" str string num *big.Int ) if len(c) > 0 { chars = c[0] } chrLen := int64(len(chars)) for len(str) < l { num, _ = crand.Int(crand.Reader, big.NewInt(chrLen)) str += string(chars[num.Int64()]) } return str } //x的y次方 func RandPow(l int) int { min := int(math.Pow10(l - 1)) max := int(math.Pow10(l) - 1) return php2go.Rand(min, max) } func RandNum() string { seed := time.Now().UnixNano() + rand.Int63() return fmt.Sprintf("%05v", rand.New(rand.NewSource(seed)).Int31n(1000000)) }