1
0
mirror of https://github.com/lus/pasty.git synced 2023-08-10 21:13:09 +03:00
pasty/internal/utils/random_string.go

17 lines
345 B
Go
Raw Normal View History

package utils
2020-08-24 21:28:09 +03:00
import (
"math/rand"
"time"
)
// RandomString returns a random string with the given length
func RandomString(characters string, length int) string {
2020-08-24 21:28:09 +03:00
rand.Seed(time.Now().UnixNano())
bytes := make([]byte, length)
for i := range bytes {
bytes[i] = characters[rand.Int63()%int64(len(characters))]
}
return string(bytes)
}