You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
rogueserver/api/utils.go

21 lines
327 B
Go

package api
import (
"crypto/rand"
)
const randRunes = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"
const lenRandRunes = len(randRunes)
func RandString(length int) string {
b := make([]byte, length)
rand.Read(b)
for i := range b {
b[i] = randRunes[int(b[i])%lenRandRunes]
}
return string(b)
}