0 Star 1 Fork 0

有点心急 / gotls

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
randomT.go 875 Bytes
一键复制 编辑 原始数据 按行查看 历史
有点心急 提交于 2024-05-17 15:51 . 24.05.17
package randomT
import (
"time"
"github.com/awnumar/fastrand"
)
// 生成随机字符串
func GenRandomStr(length int, config ...bool) string {
charset := ""
charsetList := []string{"abcdefghijklmnopqrstuvwxyz", "ABCDEFGHIJKLMNOPQRSTUVWXYZ", "0123456789", "!@#$%^&*()"}
for i, _ := range charsetList {
if i < len(config) && config[i] {
charset += charsetList[i]
}
}
result := make([]byte, length)
if len(charset) == 0 {
return ""
}
for i := 0; i < length; i++ {
randomIndex := fastrand.Intn(len(charset))
result[i] = charset[randomIndex]
}
return string(result)
}
// 生成随机数字
func GenRandomNum(num1, num2 int) int {
return fastrand.Intn(num2-num1) + num1
}
// 生成随机日期
func GenRandomDate(start, end time.Time) time.Time {
return start.Add(time.Duration(fastrand.Intn(int(end.Sub(start).Seconds()))) * time.Second)
}
Go
1
https://gitee.com/ydxj/gotls.git
git@gitee.com:ydxj/gotls.git
ydxj
gotls
gotls
v0.0.7

搜索帮助