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
|
|
|
|
|
|
|
// stringContents holds the chars a random string can contain
|
|
|
|
const stringContents = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
|
|
|
|
|
|
|
|
// RandomString returns a random string with the given length
|
|
|
|
func RandomString(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 {
|
|
|
|
bytes[i] = stringContents[rand.Int63()%int64(len(stringContents))]
|
|
|
|
}
|
|
|
|
return string(bytes)
|
|
|
|
}
|