github.com/mook-as/cf-cli@v7.0.0-beta.28.0.20200120190804-b91c115fae48+incompatible/util/randomword/generator.go (about)

     1  package randomword
     2  
     3  import (
     4  	"fmt"
     5  	"math/rand"
     6  	"strings"
     7  	"time"
     8  )
     9  
    10  const adjectives = `accountable
    11  active
    12  agile
    13  anxious
    14  appreciative
    15  balanced
    16  boisterous
    17  bold
    18  boring
    19  brash
    20  brave
    21  bright
    22  busy
    23  chatty
    24  cheerful
    25  chipper
    26  comedic
    27  courteous
    28  daring
    29  delightful
    30  empathic
    31  excellent
    32  exhausted
    33  fantastic
    34  fearless
    35  fluent
    36  forgiving
    37  friendly
    38  funny
    39  generous
    40  grateful
    41  grouchy
    42  grumpy
    43  happy
    44  hilarious
    45  humble
    46  impressive
    47  insightful
    48  intelligent
    49  interested
    50  kind
    51  lean
    52  nice
    53  noisy
    54  optimistic
    55  patient
    56  persistent
    57  proud
    58  quick
    59  quiet
    60  reflective
    61  relaxed
    62  reliable
    63  responsible
    64  responsive
    65  rested
    66  restless
    67  shiny
    68  shy
    69  silly
    70  sleepy
    71  smart
    72  spontaneous
    73  surprised
    74  sweet
    75  talkative
    76  terrific
    77  thankful
    78  timely
    79  tired
    80  turbulent
    81  unexpected
    82  wacky
    83  wise
    84  zany`
    85  
    86  const nouns = `ardvark
    87  alligator
    88  antelope
    89  baboon
    90  badger
    91  bandicoot
    92  bat
    93  bear
    94  bilby
    95  bongo
    96  bonobo
    97  buffalo
    98  bushbuck
    99  camel
   100  cassowary
   101  cat
   102  cheetah
   103  chimpanzee
   104  chipmunk
   105  civet
   106  crane
   107  crocodile
   108  dingo
   109  dog
   110  dugong
   111  duiker
   112  echidna
   113  eland
   114  elephant
   115  emu
   116  fossa
   117  fox
   118  gazelle
   119  gecko
   120  gelada
   121  genet
   122  gerenuk
   123  giraffe
   124  gnu
   125  gorilla
   126  grysbok
   127  hartebeest
   128  hedgehog
   129  hippopotamus
   130  hyena
   131  hyrax
   132  impala
   133  jackal
   134  jaguar
   135  kangaroo
   136  klipspringer
   137  koala
   138  kob
   139  kookaburra
   140  kudu
   141  lemur
   142  leopard
   143  lion
   144  lizard
   145  llama
   146  lynx
   147  manatee
   148  mandrill
   149  meerkat
   150  mongoose
   151  mouse
   152  numbat
   153  nyala
   154  okapi
   155  oribi
   156  oryx
   157  ostrich
   158  otter
   159  panda
   160  pangolin
   161  panther
   162  parrot
   163  platypus
   164  porcupine
   165  possum
   166  puku
   167  quokka
   168  quoll
   169  rabbit
   170  ratel
   171  raven
   172  reedbuck
   173  rhinocerous
   174  roan
   175  sable
   176  serval
   177  shark
   178  sitatunga
   179  springhare
   180  squirrel
   181  swan
   182  tasmaniandevil
   183  tiger
   184  topi
   185  toucan
   186  turtle
   187  wallaby
   188  warthog
   189  waterbuck
   190  wildebeest
   191  wolf
   192  wolverine
   193  wombat
   194  zebra`
   195  
   196  type Generator struct{}
   197  
   198  func NewGenerator() Generator {
   199  	rand.Seed(time.Now().UnixNano())
   200  	return Generator{}
   201  }
   202  
   203  func (gen Generator) Babble() string {
   204  	return fmt.Sprintf("%s-%s-%s", gen.RandomAdjective(), gen.RandomNoun(), gen.RandomTwoLetters())
   205  }
   206  
   207  func (Generator) RandomAdjective() string {
   208  	return randomElement(adjectives)
   209  }
   210  
   211  func (Generator) RandomNoun() string {
   212  	return randomElement(nouns)
   213  }
   214  
   215  func (Generator) RandomTwoLetters() string {
   216  	var asciiLetterA = 97
   217  	letterOne := string(rand.Intn(26) + asciiLetterA)
   218  	letterTwo := string(rand.Intn(26) + asciiLetterA)
   219  	return letterOne + letterTwo
   220  }
   221  
   222  func randomElement(fullList string) string {
   223  	wordList := strings.Split(fullList, "\n")
   224  	randomWordIndex := rand.Int() % len(wordList)
   225  
   226  	return wordList[randomWordIndex]
   227  }