mirror of
https://github.com/Mrs4s/MiraiGo.git
synced 2025-05-04 11:07:40 +08:00
21 lines
413 B
Go
21 lines
413 B
Go
package utils
|
|
|
|
import (
|
|
"bytes"
|
|
"crypto/rand"
|
|
"math/big"
|
|
)
|
|
|
|
func RandomString(len int) string {
|
|
var res string
|
|
var str = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"
|
|
b := bytes.NewBufferString(str)
|
|
length := b.Len()
|
|
bigInt := big.NewInt(int64(length))
|
|
for i := 0; i < len; i++ {
|
|
randomInt, _ := rand.Int(rand.Reader, bigInt)
|
|
res += string(str[randomInt.Int64()])
|
|
}
|
|
return res
|
|
}
|