simplier and faster casting random symbols

This commit is contained in:
Alexey Kostin 2024-03-07 12:26:26 +03:00
parent ca5c89f130
commit 27c38e6a1e

View file

@ -37,14 +37,14 @@ const (
// generate a token // generate a token
func token(length int) string { func token(length int) string {
result := "" result := make([]byte, length)
for i := 0; i < length; i++ { for i := 0; i < length; i++ {
x, err := rand.Int(rand.Reader, big.NewInt(int64(len(SYMBOLS)))) x, err := rand.Int(rand.Reader, big.NewInt(int64(len(SYMBOLS))))
if err != nil { if err != nil {
log.Fatal("Failed to generate token") log.Fatal("Failed to generate token")
} }
result = string(SYMBOLS[x.Int64()]) + result result[i] = SYMBOLS[x.Int64()]
} }
return result return string(result)
} }