-
Notifications
You must be signed in to change notification settings - Fork 66
/
rand.go
63 lines (50 loc) · 911 Bytes
/
rand.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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package casesHelper
import "math/rand"
const (
letters = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
specials = "~!@#$%^&*()_+"
)
func RandStr() (ret string) {
return RandStrWithLen(6)
}
func RandStrWithLen(length int) (ret string) {
b := make([]byte, length)
for i := range b {
b[i] = letters[rand.Intn(len(letters))]
}
ret = string(b)
return
}
func RandStrSpecial() (ret string) {
b := make([]byte, 6)
for i := range b {
b[i] = specials[rand.Intn(len(specials))]
}
ret = string(b)
return
}
func RandInt32() (ret int32) {
ret = rand.Int31()
return
}
func RandInt64() (ret int64) {
ret = rand.Int63()
return
}
func RandFloat32() (ret float32) {
ret = rand.Float32()
return
}
func RandFloat64() (ret float64) {
ret = rand.Float64()
return
}
func RandBool() (ret bool) {
r := rand.Intn(1)
if r == 0 {
ret = true
} else {
ret = false
}
return
}