mirror of
https://github.com/ChronosX88/go-gun.git
synced 2024-11-08 20:21:01 +00:00
20 lines
439 B
Go
20 lines
439 B
Go
package gun
|
|
|
|
import (
|
|
"crypto/rand"
|
|
)
|
|
|
|
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
|
|
}
|