diff options
Diffstat (limited to 'util')
-rw-r--r-- | util/rand.go | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/util/rand.go b/util/rand.go new file mode 100644 index 0000000..8502521 --- /dev/null +++ b/util/rand.go @@ -0,0 +1,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) +} |