21 lines
399 B
Go
21 lines
399 B
Go
package random
|
|
|
|
import (
|
|
"math/rand"
|
|
"time"
|
|
)
|
|
|
|
// NewRandomString geneartes random string with given size
|
|
func NewRandomString(length int) string {
|
|
rnd := rand.New(rand.NewSource(time.Now().UnixNano()))
|
|
|
|
chars := []rune("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789")
|
|
|
|
b := make([]rune, length)
|
|
for i := range b {
|
|
b[i] = chars[rnd.Intn(len(chars))]
|
|
}
|
|
|
|
return string(b)
|
|
}
|