Actually the code you posted runs, as even though there's a mistake in it (see below), it still doesn't cause a panic (just makes performance worse).
math/randgo versiongo env
Reason for panic / Solution:
RandStringBytesMaskImprSrc()RandStringBytesMaskImprSrc()rand.Sourcemath/randrand.Source()RandStringBytesMaskImprSrc()
There is a mistake in the "configuration" constants at the beginning:
const letterBytes = "abcdef0123456789"
const (
letterIdxBits = 6 // 6 bits to represent a letter index
letterIdxMask = 1<<letterIdxBits - 1 // All 1-bits, as many as letterIdxBits
letterIdxMax = 63 / letterIdxBits // # of letter indices fitting in 63 bits
)
letterIdxBitsletterBytes
letterIdxBits = 4 // 4 bits to represent a letter index
Example testing it:
var tryArr = make([]string, 10)
for i := range tryArr {
tryArr[i] = RandStringBytesMaskImprSrc(8)
}
fmt.Println(tryArr)
Output (try it on the Go Playground):
[d3e7caa6 a69c9b7d c37a613b 92d5a43b 64059c4a 4f08141b 70130c65 1546daaf fe140fcd 0d714e4d]
(Note: since the starting time on the Go playground is fixed and output is cached, you will always see these random generated strings. Run it on your machine to see random results.)