1 Star 0 Fork 0

eatmoreapple/regia

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
utils.go 788 Bytes
一键复制 编辑 原始数据 按行查看 历史
eatmoreapple 提交于 2022-07-09 13:51 . add file header and code note
// Copyright 2021 eatmoreapple. All rights reserved.
// Use of this source code is governed by a GPL style
// license that can be found in the LICENSE file.
package regia
import (
"math/rand"
"strings"
"time"
)
const randomStringChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
var maxRandomStringCharsLength = len(randomStringChars)
// Return a securely generated random string
func getRandomString(length int) string {
if length > maxRandomStringCharsLength {
length = maxRandomStringCharsLength
}
var builder strings.Builder
builder.Grow(length)
rand.Seed(time.Now().UnixNano())
for i := 0; i < length; i++ {
index := rand.Intn(maxRandomStringCharsLength)
builder.WriteString(string(randomStringChars[index]))
}
return builder.String()
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/eatmoreapple/regia.git
git@gitee.com:eatmoreapple/regia.git
eatmoreapple
regia
regia
main

搜索帮助

0d507c66 1850385 C8b1a773 1850385