-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate.go
75 lines (55 loc) · 1.5 KB
/
generate.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
64
65
66
67
68
69
70
71
72
73
74
75
package main
import "math/rand"
var alphabet = []rune("abcdefghijklmnopqrstuvwxyz")
var numbers = []rune("0123456789")
// Generates all usernames based on a given pattern with options
func generateUserNames(p Pattern, opts PatternOptions) []string {
var names []string
switch p {
// [firstname] + [numericSequence]
case firstNameNumSeq:
names = genAllPatternA(opts.firstName, opts.numSeqLen)
// [firstname] + [randomWord]
case firstNameRandWord:
names = genAllPatternB(opts.firstName, opts.wordList)
// [PatternB] + [numericSequence]
case firstNameRandWordNumSeq:
// [firstname] + [.] + [verb]
case firstNameDotVerb:
// n * [randomWord]
case randomWordTimesN:
// [PatternE] + [numericSequence]
case randomWordTimesNnumSeq:
// [randomPermutation]
case randomPermutation:
// [leetspeak(PatternA-G)]
case leetspeak:
}
return names
}
func genAllPatternA(firstName string, numSeqLen int) []string {
var names []string
allCombs := AllCombinations(numbers, numSeqLen)
for _, comb := range allCombs {
names = append(names, firstName+comb)
}
return names
}
func genAllPatternB(firstName string, wordList []string) []string {
var names []string
for _, word := range wordList {
names = append(names, firstName+word)
}
return names
}
//
// HELPER
//
// generate a random sequence choosing from a set of characters
func randomSequence(length int, alphanums []rune) string {
s := make([]rune, length)
for i := range s {
s[i] = alphanums[rand.Intn(len(alphanums))]
}
return string(s)
}