50 lines
1.1 KiB
Go
50 lines
1.1 KiB
Go
package utils
|
|
|
|
import (
|
|
"math/rand/v2"
|
|
)
|
|
|
|
// 随机生成字符串
|
|
func RandomString(l int) string {
|
|
str := "0123456789AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz"
|
|
bytes := []byte(str)
|
|
var result []byte = make([]byte, 0, l)
|
|
for i := 0; i < l; i++ {
|
|
result = append(result, bytes[rand.IntN(len(bytes))])
|
|
}
|
|
return string(result)
|
|
}
|
|
|
|
// 随机生成纯字符串
|
|
func RandomPureString(l int) string {
|
|
str := "AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz"
|
|
bytes := []byte(str)
|
|
var result []byte = make([]byte, 0, l)
|
|
for i := 0; i < l; i++ {
|
|
result = append(result, bytes[rand.IntN(len(bytes))])
|
|
}
|
|
return string(result)
|
|
}
|
|
|
|
// 随机生成纯大写字符串
|
|
func RandomPureUpString(l int) string {
|
|
str := "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
|
bytes := []byte(str)
|
|
var result []byte = make([]byte, 0, l)
|
|
for i := 0; i < l; i++ {
|
|
result = append(result, bytes[rand.IntN(len(bytes))])
|
|
}
|
|
return string(result)
|
|
}
|
|
|
|
// 随机生成数字字符串
|
|
func RandomNumber(l int) string {
|
|
str := "0123456789"
|
|
bytes := []byte(str)
|
|
var result []byte
|
|
for i := 0; i < l; i++ {
|
|
result = append(result, bytes[rand.IntN(len(bytes))])
|
|
}
|
|
return string(result)
|
|
}
|