Spaces:
Sleeping
Sleeping
File size: 512 Bytes
c5eab62 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
package utils
import (
"math/rand"
"time"
)
var randSource = rand.New(rand.NewSource(time.Now().UnixNano()))
// RandStringUsingMathRand 生成指定长度的随机字符串
func RandStringUsingMathRand(n int) string {
var letters = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789")
// 创建一个长度为 n 的切片,用来存放随机字符
result := make([]rune, n)
for i := 0; i < n; i++ {
result[i] = letters[randSource.Intn(len(letters))]
}
return string(result)
}
|