-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.go
54 lines (47 loc) · 828 Bytes
/
utils.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
package main
import (
"fmt"
"math/rand"
"unicode"
)
func choice(arr []nounPhrase) nounPhrase {
l := len(arr)
if l == 0 {
return nounPhrase{}
}
return arr[rand.Intn(l)]
}
func randWord(arr []string) string {
l := len(arr)
if l == 0 {
return ""
}
return arr[rand.Intn(l)]
}
func choiceList(arr [][]string) []string {
l := len(arr)
if l == 0 {
return make([]string, 0)
}
return arr[rand.Intn(l)]
}
func randChance(n float32) bool {
if rand.Float32()*100 < n {
return true
}
return false
}
func capitalize(s string) string {
return string(string(unicode.ToUpper(rune(s[0]))) + s[1:])
}
func joinNounPhrases(phrases []nounPhrase, sep string) string {
ret := ""
for i, ph := range phrases {
if i == 0 {
ret += ph.String()
} else {
ret += fmt.Sprintf("%s%s", sep, ph)
}
}
return ret
}