You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
23 lines
334 B
Go
23 lines
334 B
Go
2 years ago
|
package main
|
||
|
|
||
|
import (
|
||
|
"math/rand"
|
||
|
"time"
|
||
|
)
|
||
|
|
||
|
const alphabet = "1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
||
|
|
||
|
func init() {
|
||
|
rand.Seed(time.Now().UnixNano())
|
||
|
}
|
||
|
|
||
|
func GenerateRandomString(n int) string {
|
||
|
b := make([]byte, n)
|
||
|
|
||
|
for i := range b {
|
||
|
b[i] = alphabet[rand.Intn(len(alphabet))]
|
||
|
}
|
||
|
|
||
|
return string(b)
|
||
|
}
|