-
Notifications
You must be signed in to change notification settings - Fork 0
/
state.go
46 lines (34 loc) · 833 Bytes
/
state.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
package regexp2gen
import "math/rand"
const printableChars = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-_ \\\n\r"
var printableCharsNoNL = printableChars[:len(printableChars)-2]
var defaultBoundary = ' '
type state struct {
debug bool
rand *rand.Rand
limit int
// use for .
chars []rune
boundary rune
}
func (s *state) randomRunes(chars []rune, length int) []rune {
result := []rune{}
for j := 0; j < length; j++ {
r := chars[s.rand.Intn(len(chars))]
result = append(result, r)
}
return result
}
func NewState(debug bool, limit int, chars []rune, seed int64) *state {
r := rand.New(rand.NewSource(seed))
if chars == nil {
chars = []rune(printableCharsNoNL)
}
return &state{
debug: debug,
rand: r,
limit: limit,
chars: chars,
boundary: defaultBoundary,
}
}