mirror of
https://github.com/charlienet/go-mixed.git
synced 2025-07-18 08:32:40 +08:00
rnd
This commit is contained in:
20
rand/rand.go
20
rand/rand.go
@ -22,6 +22,15 @@ const (
|
|||||||
_ = allChars + "/+"
|
_ = allChars + "/+"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
randSource mrnd.Source = mrnd.NewSource(time.Now().UnixNano())
|
||||||
|
randLock sync.Mutex
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
mrnd.Seed(time.Now().UnixNano())
|
||||||
|
}
|
||||||
|
|
||||||
type charScope struct {
|
type charScope struct {
|
||||||
bytes []byte
|
bytes []byte
|
||||||
length int
|
length int
|
||||||
@ -65,9 +74,6 @@ var (
|
|||||||
AllChars = StringScope(allChars) // 所有字符
|
AllChars = StringScope(allChars) // 所有字符
|
||||||
)
|
)
|
||||||
|
|
||||||
var randSource mrnd.Source = mrnd.NewSource(time.Now().UnixNano())
|
|
||||||
var randLock sync.Mutex
|
|
||||||
|
|
||||||
// 生成指定长度的随机字符串
|
// 生成指定长度的随机字符串
|
||||||
func (scope *charScope) RandString(length int) string {
|
func (scope *charScope) RandString(length int) string {
|
||||||
n := length
|
n := length
|
||||||
@ -110,11 +116,6 @@ func RandBytes(len int) ([]byte, error) {
|
|||||||
return r, err
|
return r, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// func randNumber(max int64) (int64, error) {
|
|
||||||
// r, err := rand.Int(rand.Reader, big.NewInt(max+1))
|
|
||||||
// return r.Int64(), err
|
|
||||||
// }
|
|
||||||
|
|
||||||
func randInt63() int64 {
|
func randInt63() int64 {
|
||||||
var v int64
|
var v int64
|
||||||
|
|
||||||
@ -126,6 +127,5 @@ func randInt63() int64 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func randNumber2(max int) int {
|
func randNumber2(max int) int {
|
||||||
rnd := mrnd.New(randSource)
|
return mrnd.Intn(max)
|
||||||
return rnd.Intn(max)
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user