MCPcopy Create free account
hub / github.com/astercloud/aster / randomString

Function randomString

pkg/events/bus.go:570–577  ·  view source on GitHub ↗

randomString 生成随机字符串(使用 crypto/rand)

(n int)

Source from the content-addressed store, hash-verified

568
569// randomString 生成随机字符串(使用 crypto/rand)
570func randomString(n int) string {
571 b := make([]byte, (n+1)/2)
572 if _, err := rand.Read(b); err != nil {
573 // fallback: 使用时间戳
574 return time.Now().Format("150405.000000000")[:n]
575 }
576 return hex.EncodeToString(b)[:n]
577}

Callers 2

generateSubIDFunction · 0.70
TestRandomStringFunction · 0.70

Calls 1

ReadMethod · 0.65

Tested by 1

TestRandomStringFunction · 0.56