1 Star 0 Fork 0

UID/go-common-func

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
random.go 502 Bytes
一键复制 编辑 原始数据 按行查看 历史
UID 提交于 2024-01-19 17:34 +08:00 . init...
package funcs
import (
"math/rand"
"time"
)
// Returns an int >= min, < max
func RandomInt(min, max int) int {
return min + rand.Intn(max-min)
}
//RandomStr 随机生成字符串
func RandomStr(length int) string {
str := "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
bytes := []byte(str)
result := []byte{}
r := rand.New(rand.NewSource(time.Now().UnixNano()))
for i := 0; i < length; i++ {
result = append(result, bytes[r.Intn(len(bytes))])
}
return string(result)
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/uid/go-common-func.git
git@gitee.com:uid/go-common-func.git
uid
go-common-func
go-common-func
v1.0.8

搜索帮助