File size: 738 Bytes
619f93d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package random

import (
	"crypto/rand"
	"math/big"
	mathRand "math/rand"
	"time"

	"github.com/google/uuid"
)

var Rand *mathRand.Rand

const letterBytes = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"

func String(n int) string {
	b := make([]byte, n)
	letterLen := big.NewInt(int64(len(letterBytes)))
	for i := range b {
		idx, err := rand.Int(rand.Reader, letterLen)
		if err != nil {
			panic(err)
		}
		b[i] = letterBytes[idx.Int64()]
	}
	return string(b)
}

func Token() string {
	return "openlist-" + uuid.NewString() + String(64)
}

func RangeInt64(left, right int64) int64 {
	return mathRand.Int63n(left+right) - left
}

func init() {
	s := mathRand.NewSource(time.Now().UnixNano())
	Rand = mathRand.New(s)
}