MCPcopy Create free account
hub / github.com/cnshym/httpgo / GenerateRandomString

Function GenerateRandomString

pkg/utils/random.go:11–23  ·  view source on GitHub ↗
(length int)

Source from the content-addressed store, hash-verified

9var Charset1 = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@_=+.<>{}"
10
11func GenerateRandomString(length int) string {
12 rand.Seed(time.Now().UnixNano())
13
14 // 创建一个字节数组来存储生成的随机字符
15 b := make([]byte, length)
16
17 // 随机选择字符集中的字符并填充到字节数组中
18 for i := range b {
19 b[i] = Charset1[rand.Intn(len(Charset1))]
20 }
21
22 return string(b)
23}
24
25func GetRandomPort() (int, error) {
26 // Listen on a random port

Callers 1

mainFunction · 0.92

Calls

no outgoing calls

Tested by

no test coverage detected