bloat/util/rand.go

23 lines
366 B
Go
Raw Normal View History

2019-12-13 18:08:26 +00:00
package util
import (
"math/rand"
)
var (
runes = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890")
runes_length = len(runes)
)
func NewRandId(n int) string {
data := make([]rune, n)
for i := range data {
data[i] = runes[rand.Intn(runes_length)]
}
return string(data)
}
func NewSessionId() string {
return NewRandId(24)
}