You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
22 lines
405 B
22 lines
405 B
6 years ago
|
package node
|
||
|
|
||
|
import (
|
||
|
"math/rand"
|
||
|
"time"
|
||
|
)
|
||
|
|
||
|
var letterRunes = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")
|
||
|
|
||
|
func init() {
|
||
|
rand.Seed(time.Now().UnixNano())
|
||
|
}
|
||
|
|
||
|
// GenerateRandomString generates a random string with given length
|
||
|
func GenerateRandomString(n int) string {
|
||
|
b := make([]rune, n)
|
||
|
for i := range b {
|
||
|
b[i] = letterRunes[rand.Intn(len(letterRunes))]
|
||
|
}
|
||
|
return string(b)
|
||
|
}
|