hotime/vendor/github.com/silenceper/wechat/v2/util/string.go

19 lines
399 B
Go
Raw Permalink Normal View History

2022-05-24 05:49:25 +00:00
package util
import (
"math/rand"
"time"
)
// RandomStr 随机生成字符串
func RandomStr(length int) string {
str := "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
bytes := []byte(str)
result := []byte{}
r := rand.New(rand.NewSource(time.Now().UnixNano()))
for i := 0; i < length; i++ {
result = append(result, bytes[r.Intn(len(bytes))])
}
return string(result)
}