MCPcopy
hub / github.com/wavetermdev/waveterm / RandomHexString

Function RandomHexString

pkg/util/utilfn/utilfn.go:880–889  ·  view source on GitHub ↗

every byte is 4-bits of randomness

(numHexDigits int)

Source from the content-addressed store, hash-verified

878
879// every byte is 4-bits of randomness
880func RandomHexString(numHexDigits int) (string, error) {
881 numBytes := (numHexDigits + 1) / 2 // Calculate the number of bytes needed
882 bytes := make([]byte, numBytes)
883 if _, err := rand.Read(bytes); err != nil {
884 return "", err
885 }
886
887 hexStr := hex.EncodeToString(bytes)
888 return hexStr[:numHexDigits], nil // Return the exact number of hex digits
889}
890
891func GetJsonTag(field reflect.StructField) string {
892 jsonTag := field.Tag.Get("json")

Callers 3

checkIsReadOnlyFunction · 0.92
StartJobFunction · 0.92

Calls 1

ReadMethod · 0.45

Tested by

no test coverage detected