-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrng.go
73 lines (56 loc) · 2.39 KB
/
rng.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
package main
import (
"flag"
"fmt"
"math/rand"
"time"
)
var vowels = []string{"a", "e", "i", "o", "u"}
var extendedVowels = []string{"a", "e", "i", "o", "u", "a", "e", "i", "o", "y", "ea", "ou", "ue", "ia", "ie", "eo", "eu", "ui", "io", "oe"}
var consonants = []string{"b", "c", "d", "f", "g", "h", "j", "k", "l", "m", "n", "p", "q", "r", "s", "t", "v", "w", "x", "y", "z"}
var specialStartConsonants = []string{"bl", "br", "ch", "cl", "cr", "dr", "fl", "fr", "gl", "gr", "kh", "kl", "kr", "ph", "pl", "pr", "qu", "sc", "scr", "sh", "sk", "sl", "sm", "sn", "sp", "sq", "st", "str", "sw", "tr", "tw", "wh", "wr"}
var specialConsonants = []string{"ng", "gh", "ln", "rd", "gm", "ck", "wl", "ft", "rt", "ght", "ll", "rp", "mn", "ct", "rk", "wf", "tt", "rf", "ss", "dd", "bb", "ff", "gg", "mm", "nn", "pp", "rr", "zz", "ld", "lb", "ls", "vl", "vr"}
func pickString(strings ...string) string {
return string(strings[rand.Int31n(int32(len(strings)))])
}
func generateNormalSyllable() string {
return pickString(consonants...) + pickString(extendedVowels...)
}
func generateShortSyllable() string {
return pickString(consonants...) + pickString(vowels...)
}
func generateSpecialStartSyllable() string {
return pickString(specialStartConsonants...) + pickString(extendedVowels...)
}
func generateSpecialSyllable() string {
return pickString(specialConsonants...) + pickString(extendedVowels...)
}
func generateName() string {
word := ""
num := rand.Int31n(int32(8))
if num == 0 {
word = generateSpecialStartSyllable() + generateNormalSyllable() + generateNormalSyllable()
} else if num == 1 {
word = generateNormalSyllable() + generateSpecialSyllable() + generateNormalSyllable()
} else if num == 2 {
word = generateNormalSyllable() + generateNormalSyllable() + generateSpecialSyllable()
} else if num == 3 {
word = generateSpecialStartSyllable() + generateNormalSyllable() + generateSpecialSyllable()
} else if num == 4 {
word = generateNormalSyllable() + generateNormalSyllable() + generateNormalSyllable()
} else if num == 5 || num == 6 || num == 7 {
word = generateShortSyllable() + generateShortSyllable() + generateShortSyllable()
}
return word
}
var count int
func init() {
flag.IntVar(&count, "c", 25, "The number (or 'count') of names to be generated.")
}
func main() {
flag.Parse()
rand.Seed(time.Now().UTC().UnixNano())
for i := 0; i < count; i++ {
fmt.Println(generateName())
}
}