blob: dfece5d611b2341dd0ebe56239c3c0cece9951e8 [file] [log] [blame]
package namesgenerator
import (
type NameChecker interface {
Exists(name string) bool
var (
left = [...]string{"happy", "jolly", "dreamy", "sad", "angry", "pensive", "focused", "sleepy", "grave", "distracted", "determined", "stoic", "stupefied", "sharp", "agitated", "cocky", "tender", "goofy", "furious", "desperate", "hopeful", "compassionate", "silly", "lonely", "condescending", "naughty", "kickass", "drunk", "boring", "nostalgic", "ecstatic", "insane", "cranky", "mad", "jovial", "sick", "hungry", "thirsty", "elegant", "backstabbing", "clever", "trusting", "loving", "suspicious", "berserk", "high", "romantic", "prickly", "evil"}
// Docker 0.7.x generates names from notable scientists and hackers.
// Ada Lovelace invented the first algorithm. (thanks James Turnbull)
// Alan Turing was a founding father of computer science.
// Albert Einstein invented the general theory of relativity.
// Ambroise Pare invented modern surgery.
// Archimedes was a physicist, engineer and mathematician who invented too many things to list them here.
// Benjamin Franklin is famous for his experiments in electricity and the invention of the lightning rod.
// Charles Babbage invented the concept of a programmable computer.
// Charles Darwin established the principles of natural evolution.
// Dennis Ritchie and Ken Thompson created UNIX and the C programming language.
// Douglas Engelbart gave the mother of all demos:
// Emmett Brown invented time travel. (thanks Brian Goff)
// Enrico Fermi invented the first nuclear reactor.
// Euclid invented geometry.
// Galileo was a founding father of modern astronomy, and faced politics and obscurantism to establish scientific truth.
// Henry Poincare made fundamental contributions in several fields of mathematics.
// Isaac Newton invented classic mechanics and modern optics.
// John McCarthy invented LISP:
// Leonardo Da Vinci invented too many things to list here.
// Linus Torvalds invented Linux and Git.
// Louis Pasteur discovered vaccination, fermentation and pasteurization.
// Malcolm McLean invented the modern shipping container:
// Marie Curie discovered radioactivity.
// Muhammad ibn Jābir al-Ḥarrānī al-Battānī was a founding father of astronomy.
// Niels Bohr is the father of quantum theory.
// Nikola Tesla invented the AC electric system and every gaget ever used by a James Bond villain.
// Pierre de Fermat pioneered several aspects of modern mathematics.
// Richard Feynman was a key contributor to quantum mechanics and particle physics.
// Rob Pike was a key contributor to Unix, Plan 9, the X graphic system, utf-8, and the Go programming language.
// Stephen Hawking pioneered the field of cosmology by combining general relativity and quantum mechanics.
// Steve Wozniak invented the Apple I and Apple II.
// Werner Heisenberg was a founding father of quantum mechanics.
// William Shockley, Walter Houser Brattain and John Bardeen co-invented the transistor (thanks Brian Goff).
right = [...]string{"lovelace", "franklin", "tesla", "einstein", "bohr", "davinci", "pasteur", "nobel", "curie", "darwin", "turing", "ritchie", "torvalds", "pike", "thompson", "wozniak", "galileo", "euclid", "newton", "fermat", "archimedes", "poincare", "heisenberg", "feynman", "hawking", "fermi", "pare", "mccarthy", "engelbart", "babbage", "albattani", "ptolemy", "bell", "wright", "lumiere", "morse", "mclean", "brown", "bardeen", "brattain", "shockley"}
func GenerateRandomName(checker NameChecker) (string, error) {
retry := 5
name := fmt.Sprintf("%s_%s", left[rand.Intn(len(left))], right[rand.Intn(len(right))])
for checker != nil && checker.Exists(name) && retry > 0 {
name = fmt.Sprintf("%s%d", name, rand.Intn(10))
retry = retry - 1
if retry == 0 {
return name, fmt.Errorf("Error generating random name")
return name, nil