MCPcopy
hub / github.com/apache/devlake / RandLetterBytes

Function RandLetterBytes

backend/core/utils/strings.go:54–69  ·  view source on GitHub ↗

RandLetterBytes returns a cryptographically secure random string with given length n

(n int)

Source from the content-addressed store, hash-verified

52
53// RandLetterBytes returns a cryptographically secure random string with given length n
54func RandLetterBytes(n int) (string, errors.Error) {
55 if n < 0 {
56 return "", errors.Default.New("n must be greater than 0")
57 }
58 ret := make([]byte, n)
59 bi := big.NewInt(int64(len(letterBytes)))
60 for i := 0; i < n; i++ {
61 num, err := rand.Int(rand.Reader, bi)
62 if err != nil {
63 return "", errors.Convert(err)
64 }
65 ret[i] = letterBytes[num.Int64()]
66 }
67
68 return string(ret), nil
69}
70
71func SanitizeString(s string) string {
72 if s == "" {

Callers 1

TestRandLetterBytesFunction · 0.85

Calls 2

NewMethod · 0.65
ConvertMethod · 0.45

Tested by 1

TestRandLetterBytesFunction · 0.68