package utils import ( "crypto/rand" "math/big" ) const charset = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" // RandomString 生成指定长度的随机字符串 func RandomString(n int) string { b := make([]byte, n) for i := range b { num, _ := rand.Int(rand.Reader, big.NewInt(int64(len(charset)))) b[i] = charset[num.Int64()] } return string(b) }