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