MCPcopy Create free account
hub / github.com/RedisGraph/redisgraph-go / RandomString

Function RandomString

utils.go:70–92  ·  view source on GitHub ↗

https://medium.com/@kpbird/golang-generate-fixed-size-random-string-dd6dbd5e63c0

(n int)

Source from the content-addressed store, hash-verified

68
69// https://medium.com/@kpbird/golang-generate-fixed-size-random-string-dd6dbd5e63c0
70func RandomString(n int) string {
71 const letterBytes = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
72
73 output := make([]byte, n)
74 // We will take n bytes, one byte for each character of output.
75 randomness := make([]byte, n)
76 // read all random
77 _, err := rand.Read(randomness)
78 if err != nil {
79 panic(err)
80 }
81 l := len(letterBytes)
82 // fill output
83 for pos := range output {
84 // get random item
85 random := uint8(randomness[pos])
86 // random % 64
87 randomPos := random % uint8(l)
88 // put into output
89 output[pos] = letterBytes[randomPos]
90 }
91 return string(output)
92}
93
94func BuildParamsHeader(params map[string]interface{}) (string) {
95 header := "CYPHER "

Callers 2

TestUtilsFunction · 0.85
AddNodeMethod · 0.85

Calls

no outgoing calls

Tested by 1

TestUtilsFunction · 0.68