-
Notifications
You must be signed in to change notification settings - Fork 0
/
randomizer.go
51 lines (38 loc) · 891 Bytes
/
randomizer.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
package tools
import (
"math/rand"
"time"
)
const (
alfabetValues = "QWERTYUIOPASDFGHJKLZXCVBNM"
numbersValues = "1234567890"
symbolsValues = "!@#$%^&*<>?"
)
func NewRandomizer() *Randomizer {
return &Randomizer{}
}
type Randomizer struct{}
func (r *Randomizer) String(count int, alphabet, numbers, symbols bool) string {
return r.PseudoString(time.Now().Unix(), count, alphabet, numbers, symbols)
}
func (r *Randomizer) PseudoString(seed int64, count int, alphabet, numbers, symbols bool) string {
chars := ""
if alphabet {
chars += alfabetValues
}
if numbers {
chars += numbersValues
}
if symbols {
chars += symbolsValues
}
random := rand.New(rand.NewSource(seed))
randomLimit := len(chars)
values := make([]byte, count)
index := 0
for i := 0; i < count; i++ {
index = random.Intn(randomLimit)
values[i] = chars[index]
}
return string(values)
}