1:- module(docker_random_names,
    2          [   random_name/1,            % ?Name
    3              random_name_chk/1,        % -Name
    4              random_name_chk/2         % ?LHS, ?RHS
    5          ]).
 random_name(?Name) is nondet
Non-deterministically generates Docker-style random names. Uses random_permutation/2 and member/2, rather than random_member/2, in order to generate all possible random names by back-tracking if necessary.

The engine-based implementation has two key features: generates random permutations of both left and right sub-names independently; does not repeat until after unifying all permutations. This implies that two consecutive names will never be the same up until the boundary event between two consecutive randomisations. There is a possibility, albeit small, that the last random name from one sequence might accidentally match the first name in the next random sequence. There are 23,500 possible combinations.

The implementation is not the most efficient, but does perform accurate randomisation over all left-right name permutations.

Allows Name to collapse to semi-determinism with ground terms without continuous random-name generation since it will never match an atom that does not belong to the Docker-random name set. The engine-based non-determinism only kicks in when Name unbound.

   31random_name(Name) :-
   32    var(Name),
   33    !,
   34    setup_call_cleanup(
   35        engine_create(_, random_name_, Engine),
   36        random_name_(Name, Engine),
   37        engine_destroy(Engine)
   38    ).
   39random_name(Name) :-
   40    lhs(LHS),
   41    rhs(RHS),
   42    atomic_list_concat([LHS, RHS], '_', Name),
   43    !.
   44
   45random_name_ :-
   46    repeat,
   47    random_name_(Name),
   48    engine_yield(Name),
   49    fail.
   50
   51random_name_(Name) :-
   52    findall(LHS-RHS, (lhs(LHS), rhs(RHS)), Names0),
   53    random_permutation(Names0, Names),
   54    member(LHS-RHS, Names),
   55    atomic_list_concat([LHS, RHS], '_', Name).
   56
   57random_name_(Name, Engine) :-
   58    engine_next_reified(Engine, Term),
   59    random_name_(Term, Name, Engine).
   60
   61random_name_(the(Name), Name, _).
   62random_name_(the(_), Name, Engine) :-
   63    !,
   64    engine_next_reified(Engine, Term),
   65    random_name_(Term, Name, Engine).
   66random_name_(exception(Catcher), _, _) :-
   67    throw(Catcher).
   68random_name_(no, _, _) :-
   69    fail.
 random_name_chk(-Name:atom) is det
Generates a random Name.

Only ever fails if Name is bound and fails to match the next random Name, without testing for an unbound argument. That makes little sense, so fails unless Name is a variable.

   79random_name_chk(Name) :-
   80    var(Name),
   81    random_name_chk(LHS, RHS),
   82    atomic_list_concat([LHS, RHS], '_', Name).
 random_name_chk(?LHS:atom, ?RHS:atom) is semidet
Unifies LHS-RHS with one random name, a randomised selection from all possible names.

Note, this does not naturally work in (+, ?) or (?, +) or (+, +) modes, even if required. Predicate random_member/2 fails semi-deterministically if the given atom fails to match the randomised selection. Unifies semi-deterministically for ground atoms in order to work correctly for non-variable arguments. It collapses to failure if the argument cannot unify with random-name possibilities.

   97random_name_chk(LHS, RHS) :-
   98    random_name_chk_(LHS0, lhs(LHS0), LHS),
   99    random_name_chk_(RHS0, rhs(RHS0), RHS).
  100
  101random_name_chk_(Template, Goal, Member) :-
  102    var(Member),
  103    !,
  104    findall(Template, Goal, Members),
  105    random_member(Member, Members).
  106random_name_chk_(Member, Goal, Member) :-
  107    Goal.
  108
  109:- public
  110    lhs/1,
  111    rhs/1.  112
  113lhs(admiring).
  114lhs(adoring).
  115lhs(affectionate).
  116lhs(agitated).
  117lhs(amazing).
  118lhs(angry).
  119lhs(awesome).
  120lhs(blissful).
  121lhs(bold).
  122lhs(boring).
  123lhs(brave).
  124lhs(charming).
  125lhs(clever).
  126lhs(cocky).
  127lhs(cool).
  128lhs(compassionate).
  129lhs(competent).
  130lhs(condescending).
  131lhs(confident).
  132lhs(cranky).
  133lhs(crazy).
  134lhs(dazzling).
  135lhs(determined).
  136lhs(distracted).
  137lhs(dreamy).
  138lhs(eager).
  139lhs(ecstatic).
  140lhs(elastic).
  141lhs(elated).
  142lhs(elegant).
  143lhs(eloquent).
  144lhs(epic).
  145lhs(fervent).
  146lhs(festive).
  147lhs(flamboyant).
  148lhs(focused).
  149lhs(friendly).
  150lhs(frosty).
  151lhs(gallant).
  152lhs(gifted).
  153lhs(goofy).
  154lhs(gracious).
  155lhs(happy).
  156lhs(hardcore).
  157lhs(heuristic).
  158lhs(hopeful).
  159lhs(hungry).
  160lhs(infallible).
  161lhs(inspiring).
  162lhs(jolly).
  163lhs(jovial).
  164lhs(keen).
  165lhs(kind).
  166lhs(laughing).
  167lhs(loving).
  168lhs(lucid).
  169lhs(magical).
  170lhs(mystifying).
  171lhs(modest).
  172lhs(musing).
  173lhs(naughty).
  174lhs(nervous).
  175lhs(nifty).
  176lhs(nostalgic).
  177lhs(objective).
  178lhs(optimistic).
  179lhs(peaceful).
  180lhs(pedantic).
  181lhs(pensive).
  182lhs(practical).
  183lhs(priceless).
  184lhs(quirky).
  185lhs(quizzical).
  186lhs(recursing).
  187lhs(relaxed).
  188lhs(reverent).
  189lhs(romantic).
  190lhs(sad).
  191lhs(serene).
  192lhs(sharp).
  193lhs(silly).
  194lhs(sleepy).
  195lhs(stoic).
  196lhs(stupefied).
  197lhs(suspicious).
  198lhs(sweet).
  199lhs(tender).
  200lhs(thirsty).
  201lhs(trusting).
  202lhs(unruffled).
  203lhs(upbeat).
  204lhs(vibrant).
  205lhs(vigilant).
  206lhs(vigorous).
  207lhs(wizardly).
  208lhs(wonderful).
  209lhs(xenodochial).
  210lhs(youthful).
  211lhs(zealous).
  212lhs(zen).
  213
  214rhs(albattani).
  215rhs(allen).
  216rhs(almeida).
  217rhs(antonelli).
  218rhs(agnesi).
  219rhs(archimedes).
  220rhs(ardinghelli).
  221rhs(aryabhata).
  222rhs(austin).
  223rhs(babbage).
  224rhs(banach).
  225rhs(banzai).
  226rhs(bardeen).
  227rhs(bartik).
  228rhs(bassi).
  229rhs(beaver).
  230rhs(bell).
  231rhs(benz).
  232rhs(bhabha).
  233rhs(bhaskara).
  234rhs(black).
  235rhs(blackburn).
  236rhs(blackwell).
  237rhs(bohr).
  238rhs(booth).
  239rhs(borg).
  240rhs(bose).
  241rhs(boyd).
  242rhs(brahmagupta).
  243rhs(brattain).
  244rhs(brown).
  245rhs(buck).
  246rhs(burnell).
  247rhs(cannon).
  248rhs(carson).
  249rhs(cartwright).
  250rhs(cerf).
  251rhs(chandrasekhar).
  252rhs(chaplygin).
  253rhs(chatelet).
  254rhs(chatterjee).
  255rhs(chebyshev).
  256rhs(cohen).
  257rhs(chaum).
  258rhs(clarke).
  259rhs(colden).
  260rhs(cori).
  261rhs(cray).
  262rhs(curran).
  263rhs(curie).
  264rhs(darwin).
  265rhs(davinci).
  266rhs(dewdney).
  267rhs(dhawan).
  268rhs(diffie).
  269rhs(dijkstra).
  270rhs(dirac).
  271rhs(driscoll).
  272rhs(dubinsky).
  273rhs(easley).
  274rhs(edison).
  275rhs(einstein).
  276rhs(elbakyan).
  277rhs(elgamal).
  278rhs(elion).
  279rhs(ellis).
  280rhs(engelbart).
  281rhs(euclid).
  282rhs(euler).
  283rhs(faraday).
  284rhs(feistel).
  285rhs(fermat).
  286rhs(fermi).
  287rhs(feynman).
  288rhs(franklin).
  289rhs(gagarin).
  290rhs(galileo).
  291rhs(galois).
  292rhs(ganguly).
  293rhs(gates).
  294rhs(gauss).
  295rhs(germain).
  296rhs(goldberg).
  297rhs(goldstine).
  298rhs(goldwasser).
  299rhs(golick).
  300rhs(goodall).
  301rhs(gould).
  302rhs(greider).
  303rhs(grothendieck).
  304rhs(haibt).
  305rhs(hamilton).
  306rhs(haslett).
  307rhs(hawking).
  308rhs(hellman).
  309rhs(heisenberg).
  310rhs(hermann).
  311rhs(herschel).
  312rhs(hertz).
  313rhs(heyrovsky).
  314rhs(hodgkin).
  315rhs(hofstadter).
  316rhs(hoover).
  317rhs(hopper).
  318rhs(hugle).
  319rhs(hypatia).
  320rhs(ishizaka).
  321rhs(jackson).
  322rhs(jang).
  323rhs(jennings).
  324rhs(jepsen).
  325rhs(johnson).
  326rhs(joliot).
  327rhs(jones).
  328rhs(kalam).
  329rhs(kapitsa).
  330rhs(kare).
  331rhs(keldysh).
  332rhs(keller).
  333rhs(kepler).
  334rhs(khayyam).
  335rhs(khorana).
  336rhs(kilby).
  337rhs(kirch).
  338rhs(knuth).
  339rhs(kowalevski).
  340rhs(lalande).
  341rhs(lamarr).
  342rhs(lamport).
  343rhs(leakey).
  344rhs(leavitt).
  345rhs(lederberg).
  346rhs(lehmann).
  347rhs(lewin).
  348rhs(lichterman).
  349rhs(liskov).
  350rhs(lovelace).
  351rhs(lumiere).
  352rhs(mahavira).
  353rhs(margulis).
  354rhs(matsumoto).
  355rhs(maxwell).
  356rhs(mayer).
  357rhs(mccarthy).
  358rhs(mcclintock).
  359rhs(mclaren).
  360rhs(mclean).
  361rhs(mcnulty).
  362rhs(mendel).
  363rhs(mendeleev).
  364rhs(meitner).
  365rhs(meninsky).
  366rhs(merkle).
  367rhs(mestorf).
  368rhs(minsky).
  369rhs(mirzakhani).
  370rhs(moore).
  371rhs(morse).
  372rhs(murdock).
  373rhs(moser).
  374rhs(napier).
  375rhs(nash).
  376rhs(neumann).
  377rhs(newton).
  378rhs(nightingale).
  379rhs(nobel).
  380rhs(noether).
  381rhs(northcutt).
  382rhs(noyce).
  383rhs(panini).
  384rhs(pare).
  385rhs(pascal).
  386rhs(pasteur).
  387rhs(payne).
  388rhs(perlman).
  389rhs(pike).
  390rhs(poincare).
  391rhs(poitras).
  392rhs(proskuriakova).
  393rhs(ptolemy).
  394rhs(raman).
  395rhs(ramanujan).
  396rhs(ride).
  397rhs(montalcini).
  398rhs(ritchie).
  399rhs(rhodes).
  400rhs(robinson).
  401rhs(roentgen).
  402rhs(rosalind).
  403rhs(rubin).
  404rhs(saha).
  405rhs(sammet).
  406rhs(sanderson).
  407rhs(shamir).
  408rhs(shannon).
  409rhs(shaw).
  410rhs(shirley).
  411rhs(shockley).
  412rhs(shtern).
  413rhs(sinoussi).
  414rhs(snyder).
  415rhs(solomon).
  416rhs(spence).
  417rhs(stallman).
  418rhs(stonebraker).
  419rhs(sutherland).
  420rhs(swanson).
  421rhs(swartz).
  422rhs(swirles).
  423rhs(taussig).
  424rhs(tereshkova).
  425rhs(tesla).
  426rhs(tharp).
  427rhs(thompson).
  428rhs(torvalds).
  429rhs(tu).
  430rhs(turing).
  431rhs(varahamihira).
  432rhs(vaughan).
  433rhs(visvesvaraya).
  434rhs(volhard).
  435rhs(villani).
  436rhs(wescoff).
  437rhs(wilbur).
  438rhs(wiles).
  439rhs(williams).
  440rhs(williamson).
  441rhs(wilson).
  442rhs(wing).
  443rhs(wozniak).
  444rhs(wright).
  445rhs(wu).
  446rhs(yalow).
  447rhs(yonath).
  448rhs(zhukovsky)