Drawing a blank with respect to what to name your daughter? Don't like any of the usual names? Try the following C program. It creates names by combining the elements of the usual suspects.

<attachment name="makename.c">

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>  /* for srand(time(NULL)) */

#define MAX_ELEM_LEN 16
#define NUM_ELEMENTS 167
#define NUM_ENDINGS 10

const char elements[NUM_ELEMENTS][MAX_ELEM_LEN] =
  "be", "bell", "bern", "berth", "beth",
  "beul", "bonni", "bridgi", "brunild", "carinn",
  "cat", "cecili", "chlo", "clar", "claudi",
  "col", "colen", "consuel", "cor", "corneli",
  "cosett", "cyndi", "dan", "dari", "darl",
  "debor", "del", "dolor", "dor", "dorothe",
  "dulci", "edn", "ell", "ev", "fann",
  "fausti", "feli", "ferd", "fifi", "flor",
  "franci", "fred", "genev", "georgi", "gild",
  "gin", "giov", "giuli", "glori", "gret",
  "griseld", "gunill", "gwend", "helg", "henri",
  "hephzib", "herth", "honori", "horati", "huld",
  "hermi", "hest", "is", "jeann", "jemim",
  "jessic", "jo", "kristi", "laur", "le",
  "len", "lind", "lis", "livi", "lol",
  "lon", "lor", "lorn", "louis", "luci",
  "magd", "mari", "mir", "mil", "mind",
  "mon", "monic", "nad", "ness", "nicol",
  "non", "nor", "norm", "ori", "priscill",
  "penel", "polli", "raciel", "rebecc", "regin",
  "rhod", "robert", "ros", "sand", "shirl",
  "sib", "son", "stell", "steph", "sus",
  "sylvi", "tar", "tess", "tiff", "trici",
  "ver", "vinni", "viv", "wilm", "yol",
  "abig", "ad", "adri", "agard", "agath",
  "aid", "elaid", "albert", "alethe", "alexi",
  "alfred", "alm", "alt", "althe", "alv",
  "alvir", "amand", "ameli", "anc", "and",
  "andre", "angel", "ann", "anthe", "antoni",
  "aren", "arb", "arci", "aric", "arili",
  "arit", "arlen", "arlott", "aronic", "arri",
  "arth", "ashli", "astasi", "athsheb", "atild",
  "atri", "audre", "august", "aureli", "auror",
  "avel", "averli"

const char endings[NUM_ENDINGS][MAX_ELEM_LEN] =
  "a", "abel", "alison", "amy", "chen",
  "ie", "ietty", "icia", "ietta", "ina"

int main(const int argc, const char **argv)
  int seed = -1;
  char strout[3 * MAX_ELEM_LEN] = {0};
  int elemno_first, elemno_second, elemno_ending;

  if(argc >= 2)
    if(argv[1][0] == 'r')
      seed = time(NULL) % (NUM_ELEMENTS * (NUM_ELEMENTS - 1) * NUM_ENDINGS);
      seed = atoi(argv[1]);
  if(seed < 0)
    fputs("usage:   makename 12345   or, for a random name,   makename r\n", stderr);
    return 255;

  /* pick the elements */
  elemno_ending = seed % NUM_ENDINGS;
  seed /= NUM_ENDINGS;
  elemno_second = seed % (NUM_ELEMENTS - 1);
  seed /= (NUM_ELEMENTS - 1);
  elemno_first = seed % NUM_ELEMENTS;
  seed /= NUM_ELEMENTS;
  if(elemno_second >= elemno_first)

  /* assemble them */
  strcpy(strout, elements[elemno_first]);
  /* separate two consecutive consonants with a vowel */
  if(strchr("aeiou", elements[elemno_second][0]) == NULL)
    strcat(strout, "a");
  strcat(strout, elements[elemno_second]);
  if(strout[strlen(strout) - 1] == endings[elemno_ending][0])  /* if the last
      * letter in the second element matches the first letter in the ending */
    strout[strlen(strout) - 1] = 0; /* drop it */
  strcat(strout, endings[elemno_ending]);

  /* put it into stdout */
  return 0;


This is actually the second version of this program. The first was in QBasic and was much uglier because I failed to see the symmetry of the problem because I wrote it quickly right after seeing a film on TCM with a character named Annamanda. The main reason I wrote this in C was because I didn't know Perl. But if you're going to use one of the Perl versions listed below, use the one by m_turner, who wrote: "I wrote the 'right' perl in response to the wrong perl. It should be fully explained, if you have any questions ask."

The essence of perl is indeed that of string manipulation - and no tool better than that of the powerful regular expression engine. When understood correctly, this can make quick work of all your string tasks.

At the core of this are four lines. Just four - two of them are rather boring.

  1. Select three separate strings - two from elements, one from endings. Place an 'X' between these as a place holder.
  2. Replace two non-vowels separated by an 'X' with the two non-vowels separated by an 'a'.
  3. Replace a letter followed by an 'X' followed by the same letter again with only one instance of that letter.
  4. Replace all 'X' with nothing (remove all 'X's)

The 'qw' operator in perl is for quote words. This changes a list of words into a list of quoted words removing the need for having quotes around them or commas between the elements. It is understood that words separated by white space are being changed into a list. This is being assigned to an array called 'elements'. The '@' in front of the array says that this is indeed an array (think '@' which kind of looks like an 'a' meaning array - in perl, another name for list). The same is done for the list of words 'ends'.

The scalar ('$' looks like an 's') variable 'name' is being created which is composed of three parts. A scalar variable is something that holds one something. The something is most often a string (of letters), or a number - though there are a few other values that are scalars that are more difficult to explain.

The $name value is built of a member of the @elements list. To use access this list, the [ and ] designates which number value from the list is to be selected ('abig' is in spot 0, 'ad' is spot '1', and so on). The '$' at the start of '$elements' means that we are expecting a scalar from this value (it is possible to stuff lists into lists...). 'rand' is then called with the @elements array as a parameter. When used in a place where a number is expected, an array has the value of the number of elements in the array. When 'rand' is called with a number as a parameter, it returns a real pseudo-random number between 0 and the parameter. This number value is then used as the index into the list again as an integer (rounded down).

The '.' operator is that of string concatenation. People who have touched upon visual basic will recognize this as the & while java types will be more familiar with '+'. Here, an 'X' is placed between elements of the string to designate the boundaries between them (which are tested later).

The heart and soul of this program is three lines. Two really, the third is just cleanup.

The 's///' operator in perl is one that converts what is between the first and second '/' with what is between the second and third '/' with any options following it. This invokes the regular expression engine on the first part and our fun begins.

The [ and ] within a regular expression designate a character class - a set of characters. Here that set is all the characters except the vowels (aeiouy). This is done with the '^' meaning 'not'. Around these character classes are parentheses which stores the values matched into memory - the first item in $1, the second in $2.

The match of "lXr" becomes "lar" - the 'l' is in $1, the 'r' is in $2 and the pattern /([^aeiouy])X([^aeiouy])/$1a$2/g; matches it. This expression runs through all the string (not just the first match - the 'g' is for 'global') and replaces it every time it is found.

The second match is similar to the first, except that now any character can be matched. In regular expressions, the '.' matches any character. Once again the parentheses store the value matched. In the regular expression a '$' means the end of line and to say "that first thing" one has to use a '\' which is a special character in programing worlds to say what follows next is special. The '\1' means that first thing again. Here, we match "letter X same letter" and replace it with just that letter once. Thus 'aXa' is matched, 'a' is in $1, and the string is replaced by just 'a'.

The last thing that needs to be done is the simplest - remove all 'X' from the string, and then print it.


@elements = qw(
  abig ad adri agard agath aid albert alethe and alexi alfred alm
  alt althe alv alvir amand ameli anc andre angel ann anthe antoni
  aren arb arci aric arili arit arlen arlott aronic arri arth ashli
  astasi athsheb atild atri audre august aureli auror avel averli
  bell be bern berth beth beul bonni bridgi brunild carinn cat cecili
  chlo clar claudi col colen consuel corneli cor cosett cyndi dan
  dari darl debor del dolor dulci dorothe dor edn elaid ell ev fann
  fausti feli ferd fifi flor franci fred genev georgi gild gin giov 
  giuli glori gret griseld gunill gwend helg hephzib henri herth
  honori horati huld hermi hest is jessic jeann jemim jo kristi laur
  le len lind lis livi lol lon lor lorn louis luci magd mari mir mil
  mind mon monic nad ness nicol non nor norm ori priscill penel polli
  raciel rebecc regin rhod robert ros sand shirl sib son stell steph
  sus sylvi tar tess tiff trici ver vinni viv wilm yol);

@ends = qw(a abel alison amy chen ie ietty icia ietta ina);

$name =
    $elements[rand @elements] . 'X' .
    $elements[rand @elements] . 'X' .
    $ends[rand @ends];

$name =~ s/([^aeiouy])X([^aeiouy])/$1a$2/g;
$name =~ s/(.)X\1/$1/g;
$name =~ s/X//g;

print ucfirst($name), "\n";

Log in or registerto write something here or to contact authors.