-
Notifications
You must be signed in to change notification settings - Fork 0
/
angen.go
51 lines (43 loc) · 894 Bytes
/
angen.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 main
import (
_ "embed"
"fmt"
"math/rand"
"strings"
"time"
)
const (
delimiters = " _|,;:.!?~@#$%^&+-*=/"
delimitersMax = len(delimiters) - 1
)
var (
//go:embed adjectives.txt
adjectivesTxt string
//go:embed names.txt
namesTxt string
adjectivesMax int
namesMax int
adjectives []string
names []string
)
func Generate() string {
rand.Seed(time.Now().UnixNano())
adjectivesIdx := rand.Intn(adjectivesMax)
namesIdx := rand.Intn(namesMax)
delimitersIdx := rand.Intn(delimitersMax)
number := rand.Intn(999)
return fmt.Sprintf(
"%s%s%s%s%03d",
adjectives[adjectivesIdx],
string(delimiters[delimitersIdx]),
names[namesIdx],
string(delimiters[delimitersIdx]),
number,
)
}
func init() {
adjectives = strings.Split(adjectivesTxt, "\n")
names = strings.Split(namesTxt, "\n")
adjectivesMax = len(adjectives) - 1
namesMax = len(names) - 1
}