go-gun/gun/util.go

20 lines
439 B
Go
Raw Normal View History

2019-02-20 20:54:46 +00:00
package gun
2019-02-22 09:23:14 +00:00
import (
"crypto/rand"
)
2019-02-20 20:54:46 +00:00
const randChars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
func randString(n int) (s string) {
// We accept that a multiple of 64 is %'d on 62 potentially favoring 0 or 1 more, but we don't care
byts := make([]byte, n)
if _, err := rand.Read(byts); err != nil {
panic(err)
}
for _, byt := range byts {
s += string(randChars[int(byt)%len(randChars)])
}
return s
}