diff options
author | r <r@freesoftwareextremist.com> | 2019-12-13 18:08:26 +0000 |
---|---|---|
committer | r <r@freesoftwareextremist.com> | 2019-12-13 18:26:24 +0000 |
commit | 5e4da01c3ae3ae2e870faba9085d9d9213c01c29 (patch) | |
tree | 39d6f1e76b901549f194ddbac3c6cb82e0abd019 /util | |
download | bloat-5e4da01c3ae3ae2e870faba9085d9d9213c01c29.tar.gz bloat-5e4da01c3ae3ae2e870faba9085d9d9213c01c29.zip |
Initial commit
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) +} |