Created
September 28, 2013 11:45
-
-
Save Velrok/6741269 to your computer and use it in GitHub Desktop.
Random name generator using combining adjectives with animals.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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)) |
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")
Wouldn't it be faster to use vectors then for the Olog32N lookup on rand and disj?
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
Realizing all
for
combinations withshuffle
is a really expensive way to ensure that the seq that youtake
from it has unique values.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.random-names-2
doesn't behave like a seq and it's kinda dumb, but it at least guarantees unique results.This all is of course just for fun, but
random-names-3
(the next evolution) would be smarter and written withlazy-seq
and drain from the adjectives pool & animals pool as it's consumed.