// A fast random []byte generator. The default Source is used, which // is safe for concurrent use by multiple goroutines. The default Source // is seeded at package init. package rndstr import ( "math/rand" "time" ) func init() { rand.Seed(time.Now().UnixNano()) } const letterBytes = "1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-_" const ( letterIdxBits = 6 // 6 bits to represent a letter index letterIdxMask = 1<= 0; { if remain == 0 { cache, remain = rand.Int63(), letterIdxMax } idx := int(cache & letterIdxMask) b[i] = letterBytes[idx] i-- cache >>= letterIdxBits remain-- } } // Returns []byte of 'n' length filled with random characters func GetBytes(n int) []byte { b := make([]byte, n) PutBytes(b) return b }