-
Notifications
You must be signed in to change notification settings - Fork 0
/
random.go
32 lines (25 loc) · 830 Bytes
/
random.go
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
package nonce
import (
"math/rand"
"time"
)
const charset = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
var seededRand *rand.Rand = rand.New(rand.NewSource(time.Now().UnixNano()))
// GenerateRandomString returns a randomized string
func GenerateRandomString(stringLen int) string {
b := make([]byte, stringLen)
for i := range b {
b[i] = charset[seededRand.Intn(len(charset))]
}
return string(b)
}
const upperCharset = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
var upperSeededRand *rand.Rand = rand.New(rand.NewSource(time.Now().UnixNano()))
// GenerateRandomStringUpperOnly returns a randomized string
func GenerateRandomStringUpperOnly(stringLen int) string {
b := make([]byte, stringLen)
for i := range b {
b[i] = upperCharset[upperSeededRand.Intn(len(upperCharset))]
}
return string(b)
}