File tree Expand file tree Collapse file tree 5 files changed +75
-38
lines changed Expand file tree Collapse file tree 5 files changed +75
-38
lines changed Original file line number Diff line number Diff line change 1
1
module github.com/symmetric-project/ngen
2
2
3
3
go 1.17
4
+
5
+ require github.com/iancoleman/strcase v0.2.0
Original file line number Diff line number Diff line change
1
+ github.com/iancoleman/strcase v0.2.0 h1:05I4QRnGpI0m37iZQRuskXh+w77mr6Z41lwQzuHLwW0 =
2
+ github.com/iancoleman/strcase v0.2.0 /go.mod h1:iwCmte+B7n89clKwxIoIXy/HfoL7AsD47ZCWhYzw7ho =
Load Diff This file was deleted.
Original file line number Diff line number Diff line change
1
+ package ngen
2
+
3
+ import (
4
+ "math"
5
+ "math/rand"
6
+ "os"
7
+ "time"
8
+
9
+ "github.com/iancoleman/strcase"
10
+ )
11
+
12
+ var adjectives []string
13
+ var adverbs []string
14
+ var nouns []string
15
+ var verbs []string
16
+
17
+ func init () {
18
+ rand .Seed (time .Now ().UnixNano ())
19
+ var err error
20
+ adjectives , err = readLines ("./words/adjectives.txt" )
21
+ if err != nil {
22
+ os .Exit (1 )
23
+ }
24
+ adverbs , err = readLines ("./words/adverbs.txt" )
25
+ if err != nil {
26
+ os .Exit (1 )
27
+ }
28
+ nouns , err = readLines ("./words/nouns.txt" )
29
+ if err != nil {
30
+ os .Exit (1 )
31
+ }
32
+ verbs , err = readLines ("./words/verbs.txt" )
33
+ if err != nil {
34
+ os .Exit (1 )
35
+ }
36
+ }
37
+
38
+ func getRandomStringFromStringArray (arr []string ) string {
39
+ randomRawIndex := rand .Float64 () * float64 (len (arr )- 1 )
40
+ randomIndex := int (math .Round (randomRawIndex ))
41
+ return arr [randomIndex ]
42
+ }
43
+
44
+ func adjective () string {
45
+ return getRandomStringFromStringArray (adjectives )
46
+ }
47
+
48
+ func adverb () string {
49
+ return getRandomStringFromStringArray (adverbs )
50
+ }
51
+
52
+ func noun () string {
53
+ return getRandomStringFromStringArray (nouns )
54
+ }
55
+
56
+ func verb () string {
57
+ return getRandomStringFromStringArray (verbs )
58
+ }
59
+
60
+ func Generate () string {
61
+ return strcase .ToCamel (adjective () + "-" + noun ())
62
+ }
Original file line number Diff line number Diff line change
1
+ package ngen
2
+
3
+ import (
4
+ "testing"
5
+ )
6
+
7
+ func TestPrintName (t * testing.T ) {
8
+ t .Log (Generate ())
9
+ }
You can’t perform that action at this time.
0 commit comments