-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrandname.go
More file actions
39 lines (28 loc) · 1.1 KB
/
randname.go
File metadata and controls
39 lines (28 loc) · 1.1 KB
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
package randname
import (
"fmt"
"math/rand"
"strings"
"time"
)
// This is in a separate package from main.go because this is meant to be used
// as a library, while main.go is meant to built as a binary.
// https://stackoverflow.com/questions/14284375/can-i-have-a-library-and-binary-with-the-same-name
// GenerateLowerCase produces a lower case name using a random adjective and noun.
// delim is added as a delimiter between words.
func GenerateLowerCase(delim string) string {
rand.Seed(time.Now().UTC().UnixNano())
adj := Adjectives[rand.Intn(len(Adjectives))]
noun := Colours[rand.Intn(len(Colours))]
return fmt.Sprintf("%s%s%s", adj, delim, noun)
}
// GenerateCamelCase produces a camel case name using a random adjective and noun.
// delim is added as a delimiter between words.
func GenerateCamelCase(delim string) string {
rand.Seed(time.Now().UTC().UnixNano())
adj := Adjectives[rand.Intn(len(Adjectives))]
noun := Colours[rand.Intn(len(Colours))]
titledAdj := strings.Title(string(adj))
titledNoun := strings.Title(string(noun))
return fmt.Sprintf("%s%s%s", titledAdj, delim, titledNoun)
}