Random Names

What do you do on a lazy Sunday? Write programs of course…

What do you do on a lazy Sunday? Write programs of course! I was reading Tim Hartnell’s book Creating Adventure Games On Your Computer and ran across a little gem for generating random names. It is short and sweet and easily converted into Perl.

I spent more time making it pretty than actually converting the BASIC code. Typical me. Here are a few of the names it spat out at me:

Bojgo, Varoica, Bukpaoe, Savi, Dekzoza, Xein, Iondilo, Dokwota

Select here to generate your own.

For those interested, here is the code I use to generate the names. It is identical to the BASIC in function, down to using ASCII codes. Much of the routine is dedicated to printing out pretty HTML rows and columns. I do lowercase the name Upon further reflection, I should have capitalized the first letter since these are supposed to be proper nouns.

  my @verbs = (65, 69, 73, 79, 85);
  my $col = 4;
  while ($col--) {
  print qq~<div class="col-xs-6 col-sm-3">~;
  my $row = 10;
  while ($row--) {
  my $word; my $letter = 0;
  my $size = 4+int(rand(4));
  while ($letter++ < $size) {
  my $char;
  while (!$char) {
  $char = 66 + int(rand(25));
  if (rand(1)>.7 and ($char==69 or $char==73 or $char==79 or $char=85)) { $char = undef }
  if ($letter==2 or $letter==5 or $letter==7) { $char=$verbs[int(rand(5))] }
  $word .= chr($char);
  $word = lc($word);
  print qq~\u$word
  print qq~</div>\n~;

Leave me a comment if you find this useful. I’m thinking I should hook this into some sort of MAD LIBS generator. Maybe a project for another day.

Comments on this article:

No comments so far.

Write a comment:

Type The Letters You See.
[captcha image][captcha image][captcha image][captcha image][captcha image][captcha image]
not case sensitive