woj-server/pkg/utils/string.go

17 lines
270 B
Go
Raw Normal View History

2022-09-07 23:34:37 +08:00
package utils
import (
"math/rand"
)
var letters = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789")
func RandomString(n int) string {
s := make([]rune, n)
for i := range s {
s[i] = letters[rand.Intn(len(letters))]
}
return string(s)
}