代码拉取完成,页面将自动刷新
package xgen
import (
"crypto/rand"
"github.com/lithammer/shortuuid/v3"
uuid "github.com/satori/go.uuid"
"math/big"
"strings"
)
func Uuid() string {
return uuid.NewV4().String()
}
func UuidShort() string {
return shortuuid.New()
}
func UuidNoSeparator() string {
return strings.Replace(Uuid(), "-", "", -1)
}
func RandInt(min, max int64) int64 {
// calculate the max we will be using
bg := big.NewInt(max - min)
// get big.Int between 0 and bg
// in this case 0 to 20
n, err := rand.Int(rand.Reader, bg)
if err != nil {
panic(err)
}
// add n to min to support the passed in range
return n.Int64() + min
}
const (
LettersLetter = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
LettersUpperCaseLetter = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
LettersNumber = "0123456789"
LettersNumberNoZero = "23456789"
LettersSymbol = "~`!@#$%^&*()_-+={[}]|\\:;\"'<,>.?/"
)
func RandString(n int, letters ...string) (string, error) {
lettersDefaultValue := LettersLetter + LettersNumber + LettersSymbol
if len(letters) > 0 {
lettersDefaultValue = ""
for _, letter := range letters {
lettersDefaultValue = lettersDefaultValue + letter
}
}
bytes := make([]byte, n)
_, err := rand.Read(bytes)
if err != nil {
return "", err
}
for i, b := range bytes {
bytes[i] = lettersDefaultValue[b%byte(len(lettersDefaultValue))]
}
return string(bytes), nil
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。