-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrandom.go
53 lines (42 loc) · 785 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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package random
func readNum() int64 {
if !StatsRandPool() {
return randFromReader()
}
return randFromPool()
}
func Int8() int8 {
return int8(readNum())
}
func Uint8() uint8 {
return uint8(readNum())
}
func Int16() int16 {
return int16(readNum())
}
func Uint16() uint16 {
return uint16(readNum())
}
func Int32() int32 {
return int32(readNum())
}
func Uint32() uint32 {
return uint32(readNum())
}
func Int64() int64 {
return readNum()
}
func Uint64() uint64 {
return uint64(readNum())
}
func String(size int) string {
return StringWithDict(size, defaultDict)
}
func StringWithDict(size int, dict []byte) string {
res := make([]byte, size, size)
dictLen := uint8(len(dict))
for i := 0; i < size; i++ {
res[i] = dict[Uint8()%dictLen]
}
return string(res)
}