aboutsummaryrefslogtreecommitdiff
path: root/util/rand.go
blob: 850252194f548cd38d251938352b5df4601b88fa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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)
}