first commit
This commit is contained in:
40
pkg/common/HyTools/RandTools.go
Normal file
40
pkg/common/HyTools/RandTools.go
Normal file
@ -0,0 +1,40 @@
|
||||
package HyTools
|
||||
|
||||
import (
|
||||
"math/rand"
|
||||
"time"
|
||||
)
|
||||
|
||||
func RandInt64(min, max int64) int64 {
|
||||
if min >= max || min == 0 || max == 0 {
|
||||
return max
|
||||
}
|
||||
return rand.Int63n(max-min) + min
|
||||
}
|
||||
|
||||
// 获取随机数字字符串
|
||||
func GetRandNumber(l int) string {
|
||||
|
||||
str := "0123456789"
|
||||
bytes := []byte(str)
|
||||
result := []byte{}
|
||||
r := rand.New(rand.NewSource(time.Now().UnixNano()))
|
||||
for i := 0; i < l; i++ {
|
||||
result = append(result, bytes[r.Intn(len(bytes))])
|
||||
}
|
||||
return string(result)
|
||||
|
||||
}
|
||||
|
||||
// 生成随机字符串
|
||||
func GetRandomString(l int) string {
|
||||
|
||||
str := "0123456789abcdefghijklmnopqrstuvwxyz"
|
||||
bytes := []byte(str)
|
||||
result := []byte{}
|
||||
r := rand.New(rand.NewSource(time.Now().UnixNano()))
|
||||
for i := 0; i < l; i++ {
|
||||
result = append(result, bytes[r.Intn(len(bytes))])
|
||||
}
|
||||
return string(result)
|
||||
}
|
||||
Reference in New Issue
Block a user