mirror of
https://github.com/usual2970/certimate.git
synced 2025-06-08 13:39:53 +00:00
25 lines
519 B
Go
25 lines
519 B
Go
package rand
|
|
|
|
import (
|
|
"math/rand"
|
|
"time"
|
|
)
|
|
|
|
// Deprecated: this will be removed in the future.
|
|
// 随机生成指定长度字符串
|
|
func RandStr(n int) string {
|
|
seed := time.Now().UnixNano()
|
|
source := rand.NewSource(seed)
|
|
random := rand.New(source)
|
|
|
|
letters := []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789")
|
|
|
|
// 使用循环生成指定长度的字符串
|
|
result := make([]rune, n)
|
|
for i := range result {
|
|
result[i] = letters[random.Intn(len(letters))]
|
|
}
|
|
|
|
return string(result)
|
|
}
|