Skip to content

Instantly share code, notes, and snippets.

@Velrok
Created September 28, 2013 11:45
Show Gist options
  • Star 15 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Velrok/6741269 to your computer and use it in GitHub Desktop.
Save Velrok/6741269 to your computer and use it in GitHub Desktop.
Random name generator using combining adjectives with animals.
(def adjectives [
"adorable"
"adventurous"
"aggressive"
"alert"
"attractive"
"average"
"beautiful"
"blue-eyed "
"bloody"
"blushing"
"bright"
"clean"
"clear"
"cloudy"
"colorful"
"crowded"
"cute"
"dark"
"drab"
"distinct"
"dull"
"elegant"
"excited"
"fancy"
"filthy"
"glamorous"
"gleaming"
"gorgeous"
"graceful"
"grotesque"
"handsome"
"homely"
"light"
"long"
"magnificent"
"misty"
"motionless"
"muddy"
"old-fashioned"
"plain"
"poised"
"precious"
"quaint"
"shiny"
"smoggy"
"sparkling"
"spotless"
"stormy"
"strange"
"ugly"
"ugliest"
"unsightly"
"unusual"
"wide-eyed "
"alive"
"annoying"
"bad"
"better"
"beautiful"
"brainy"
"breakable"
"busy"
"careful"
"cautious"
"clever"
"clumsy"
"concerned"
"crazy"
"curious"
"dead"
"different"
"difficult"
"doubtful"
"easy"
"expensive"
"famous"
"fragile"
"frail"
"gifted"
"helpful"
"helpless"
"horrible"
"important"
"impossible"
"inexpensive"
"innocent"
"inquisitive"
"modern"
"mushy"
"odd"
"open"
"outstanding"
"poor"
"powerful"
"prickly"
"puzzled"
"real"
"rich"
"shy"
"sleepy"
"stupid"
"super"
"talented"
"tame"
"tender"
"tough"
"uninterested"
"vast"
"wandering"
"wild"
"wrong"
"agreeable"
"amused"
"brave"
"calm"
"charming"
"cheerful"
"comfortable"
"cooperative"
"courageous"
"delightful"
"determined"
"eager"
"elated"
"enchanting"
"encouraging"
"energetic"
"enthusiastic"
"excited"
"exuberant"
"fair"
"faithful"
"fantastic"
"fine"
"friendly"
"funny"
"gentle"
"glorious"
"good"
"happy"
"healthy"
"helpful"
"hilarious"
"jolly"
"joyous"
"kind"
"lively"
"lovely"
"lucky"
"nice"
"obedient"
"perfect"
"pleasant"
"proud"
"relieved"
"silly"
"smiling"
"splendid"
"successful"
"thankful"
"thoughtful"
"victorious"
"vivacious"
"witty"
"wonderful"
"zealous"
"zany"])
(def animals [
"aardvark"
"albatross"
"alligator"
"alpaca"
"ant"
"anteater"
"antelope"
"ape"
"armadillo"
"herd"
"baboon"
"badger"
"barracuda"
"bat"
"bear"
"beaver"
"bee"
"bison"
"boar"
"galago"
"butterfly"
"camel"
"caribou"
"cat"
"caterpillar"
"cattle"
"chamois"
"cheetah"
"chicken"
"chimpanzee"
"chinchilla"
"chough"
"clam"
"cobra"
"cockroach"
"cod"
"cormorant"
"coyote"
"crab"
"herd"
"crocodile"
"crow"
"curlew"
"deer"
"dinosaur"
"dog"
"dolphin"
"donkey"
"dotterel"
"dove"
"dragonfly"
"duck"
"dugong"
"dunlin"
"eagle"
"echidna"
"eel"
"elephant"
"elk"
"emu"
"falcon"
"ferret"
"finch"
"fish"
"flamingo"
"fly"
"fox"
"frog"
"gaur"
"gazelle"
"gerbil"
"giraffe"
"gnat"
"goat"
"goose"
"goldfish"
"gorilla"
"goshawk"
"grasshopper"
"grouse"
"guanaco"
"poultry"
"herd"
"gull"
"hamster"
"hare"
"hawk"
"hedgehog"
"heron"
"herring"
"hippopotamus"
"hornet"
"horse"
"human"
"hummingbird"
"hyena"
"jackal"
"jaguar"
"jay"
"jellyfish"
"kangaroo"
"koala"
"kouprey"
"kudu"
"lapwing"
"lark"
"lemur"
"leopard"
"lion"
"llama"
"lobster"
"locust"
"loris"
"louse"
"lyrebird"
"magpie"
"mallard"
"manatee"
"marten"
"meerkat"
"mink"
"monkey"
"moose"
"mouse"
"mosquito"
"mule"
"narwhal"
"newt"
"nightingale"
"octopus"
"okapi"
"opossum"
"oryx"
"ostrich"
"otter"
"owl"
"ox"
"oyster"
"parrot"
"partridge"
"peafowl"
"pelican"
"penguin"
"pheasant"
"pig"
"pigeon"
"pony"
"porcupine"
"porpoise"
"quail"
"quelea"
"rabbit"
"raccoon"
"rat"
"raven"
"herd"
"reindeer"
"rhinoceros"
"ruff"
"salamander"
"salmon"
"sandpiper"
"sardine"
"scorpion"
"herd"
"seahorse"
"shark"
"sheep"
"shrew"
"shrimp"
"skunk"
"snail"
"snake"
"spider"
"squid"
"squirrel"
"starling"
"stingray"
"stinkbug"
"stork"
"swallow"
"swan"
"tapir"
"tarsier"
"termite"
"tiger"
"toad"
"trout"
"poultry"
"turtle"
"vulture"
"wallaby"
"walrus"
"wasp"
"carabeef"
"weasel"
"whale"
"wolf"
"wolverine"
"wombat"
"woodcock"
"woodpecker"
"worm"
"wren"
"yak"
"zebra"
])
(defn random-names [& {:keys [seperator]
:or {seperator " "}}]
(shuffle
(for [adjective adjectives
animal animals]
(str adjective seperator animal))))
; (take 5 (random-names))
@danneu
Copy link

danneu commented Sep 29, 2013

Realizing all for combinations with shuffle is a really expensive way to ensure that the seq that you take from it has unique values.

(defn random-name []
  (clojure.string/join "-" (map rand-nth [adjectives animals])))

For fun, here are two naive approaches that came to mind:

random-names-1 lazily generates a seq of names but they aren't guaranteed to be unique.

(defn random-names-1 []
  (repeatedly random-name))

(take 3 (random-names-1))  ;=> ("breakable-squirrel" "poor-chamois" "amused-ant")

random-names-2 doesn't behave like a seq and it's kinda dumb, but it at least guarantees unique results.

(defn random-names-2 [n]
  (loop [names #{}]
    (if (= n (count names))
      names
      (recur (conj names (random-name))))))

(random-names-2 3)  ;=> #{"clear-wolverine" "muddy-antelope" "beautiful-locust"}

This all is of course just for fun, but random-names-3 (the next evolution) would be smarter and written with lazy-seq and drain from the adjectives pool & animals pool as it's consumed.

@gsinclair
Copy link

My contribution produces a lazy sequence of unique names. The drawback is the O(n) selection of a random element from a set.

Note that the adjectives and animals are sets.

(def adjectives #{
  "adorable"
  "adventurous"
  "aggressive"
  "alert"
  "attractive"})

(def animals #{
  "aardvark"
  "albatross"
  "alligator"
  "alpaca"
  "ant"})

(defn random-element-from-set [s]
  (rand-nth (seq s)))

(defn random-names [adjectives animals]
  (cond
    (or (empty? adjectives) (empty? animals))
      nil
    :else
      (lazy-seq
        (let [adj (random-element-from-set adjectives)
              ani (random-element-from-set animals)]
          (cons (str adj "-" ani)
                (random-names (disj adjectives adj)
                              (disj animals ani)))))))

(random-names adjectives animals)
;= ("attractive-ant" "adorable-aardvark" "adventurous-albatross" "aggressive-alpaca" "alert-alligator")

@danneu
Copy link

danneu commented Sep 29, 2013

@gsinclair:

Wouldn't it be faster to use vectors then for the Olog32N lookup on rand and disj?

@Velrok
Copy link
Author

Velrok commented Oct 2, 2013

Thanks for the feedback!

I didn't know that shuffle realizes the lazy seq it is given. Good to know.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment