home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / misc / volume6 / rndname < prev    next >
Text File  |  1989-03-25  |  8KB  |  238 lines

  1. Newsgroups: comp.sources.misc
  2. From: allbery@uunet.UU.NET (Brandon S. Allbery - comp.sources.misc)
  3. Subject: v06i079: Random Name Generator for RPGs
  4. Reply-To: slocum@hi-csc.UUCP
  5.  
  6. Posting-number: Volume 6, Issue 79
  7. Submitted-by: slocum@hi-csc.UUCP
  8. Archive-name: rndname
  9.  
  10. This program is a very simple random name generator for use
  11. with roleplaying games.  It produces surprisingly good names
  12. for the very simple method used.  The names tend to be exotic, 
  13. since 'X' and  'Z' have the same chance of coming up as 'T' and 
  14. 'N'.  Many of the names have a Japanese or African flavor.  Some 
  15. of my favorites came in the first page generated: Zozaras, Lyxam, 
  16. Rux, and Zelica.  
  17.  
  18. The program 'name.c' produces the names, and two scripts are 
  19. included to formats them into pages: names.csh and names.sh, 
  20. for C-shell and Bourne shell, respectively.  Instructions for 
  21. changing the distribution of letters are given in comments in 
  22. name.c.
  23.  
  24. These programs have been tested on an Apollo DN330 with both
  25. BSD4.2 and Sys V, and on BSD4.3.  The makefile and names.csh 
  26. script have Sys V versions commented out.  The changes for
  27. MS-DOS similar to the ones used here have been tested, but
  28. the specific changes for MS-DOS in this program have not.
  29.  
  30. Send any changes or updates to me:
  31.  
  32. Brett Slocum   UUCP: ...uunet!hi-csc!slocum
  33.                Arpa: hi-csc!slocum@uunet.uu.net
  34. "My name is Inigo Montoya. You killed my father. Prepare to die."
  35.  
  36. #--------------------------------CUT HERE-------------------------------------
  37.  
  38. # This is a shell archive.  Remove anything before this line, then
  39. # unpack it by saving it in a file and typing "sh file".  (Files
  40. # unpacked will be owned by you and have default permissions.)
  41. #
  42. # This archive contains:
  43. # README Makefile name.c names.csh names.sh
  44.  
  45. echo x - README
  46. cat > "README" << '//E*O*F README//'
  47. This program is a very simple random name generator for use
  48. with roleplaying games.  It produces surprisingly good names
  49. for the very simple method used.  The names tend to be exotic, 
  50. since 'X' and  'Z' have the same chance of coming up as 'T' and 
  51. 'N'.  Many of the names have a Japanese or African flavor.  Some 
  52. of my favorites came in the first page generated: Zozaras, Lyxam, 
  53. Rux, and Zelica.  
  54.  
  55. The program 'name.c' produces the names, and two scripts are 
  56. included to formats them into pages: names.csh and names.sh, 
  57. for C-shell and Bourne shell, respectively.  Instructions for 
  58. changing the distribution of letters are given in comments in 
  59. name.c.
  60.  
  61. These programs have been tested on an Apollo DN330 with both
  62. BSD4.2 and Sys V, and on BSD4.3.  The makefile and names.csh 
  63. script have Sys V versions commented out.  The changes for
  64. MS-DOS similar to the ones used here have been tested, but
  65. the specific changes for MS-DOS in this program have not.
  66.  
  67. Send any changes or updates to me:
  68.  
  69. Brett Slocum   UUCP: ...uunet!hi-csc!slocum
  70.                Arpa: hi-csc!slocum@uunet.uu.net
  71. "My name is Inigo Montoya. You killed my father. Prepare to die."
  72.  
  73. //E*O*F README//
  74.  
  75. echo x - Makefile
  76. cat > "Makefile" << '//E*O*F Makefile//'
  77. #  makefile for name.c
  78. #
  79. #       Comment out the BSD line if you're on System V
  80. #       Comment out the SYSV line if you're using Berkely Unix.
  81.  
  82. # SYSTEM = -DSYSV 
  83. SYSTEM = -DBSD
  84.  
  85. CFLAGS = -O $(SYSTEM)
  86.  
  87. name:   name.c
  88.     cc -o name $(CFLAGS) name.c
  89.  
  90. //E*O*F Makefile//
  91.  
  92. echo x - name.c
  93. cat > "name.c" << '//E*O*F name.c//'
  94. /**************************************************************************
  95.  *      name - prints random names                                        * 
  96.  *  Copyright 1988 by Brett Slocum.  All rights reserved.                 *
  97.  *  Permission is granted to distribute, modify, or use portions of this  *
  98.  *  code in other programs, as long as this notice remains intact.        *
  99.  *  This program or its derivatives may not be sold for profit without    *
  100.  *  permission.                                                           *
  101.  *                                                                        *
  102.  *  UNIX  Version: Brett Slocum UUCP: ...uunet!hi-csc!slocum              *
  103.  *                              ARPA: slocum@hi-csc.honeywell.com         *
  104.  *  Changes were suggested by Geoff Kimbrough <geoff@ism780c.isc.com>     *
  105.  *                                                                        *
  106.  *  IBM Microsoft C v5.0 changes by Loyd Blankenship on 11-15-88          *
  107.  *                            UUCP: ...rutgers.edu!cs.utexas.edu!nth!loyd *
  108.  *                                                                        *
  109.  *  Version 2 by Brett Slocum 3/22/89 : various cleanups, features, etc.  *
  110.  *                                                                        *
  111.  **************************************************************************/
  112.  
  113. #ifdef SYSV
  114. #include <string.h>
  115. #define srandom srand48
  116. #define random lrand48
  117. #endif
  118.  
  119. #ifdef BSD
  120. #include <strings.h>
  121. #endif
  122.  
  123. #ifdef MSC
  124. #include <string.h>
  125. #include <stdio.h>
  126. #include <stdlib.h>
  127. #include <time.h>
  128. #define srandom srand
  129. #define random rand
  130. #endif
  131.  
  132. #include <ctype.h>
  133.  
  134. #define YES 1
  135. #define NO 0
  136. #define MAXNAME 30
  137. #define MINLENGTH 3
  138. #define RANGE 6
  139. #define rnd(n) (unsigned)(random() % (n))
  140.  
  141. /*
  142.    Since "y" appears twice, once in each array, all other 
  143.    letters, except "'", are doubled to keep the distribution even.
  144.    By adding or deleting the letters from these arrays, you
  145.    can change the frequency of appearance of the letters,
  146.    (i.e. by adding "e" and "t" and deleting "z" and "q",
  147.    a distribution closer to English could be made.)
  148.    An interesting idea would be to use as many repetitions
  149.    of each letter as are found in a Scrabble (tm) game.
  150. */
  151.  
  152.  char vowels[] = "aaeeiioouuy'";
  153.  char cons[] = "bbccddffgghhjjkkllmmnnppqqrrssttvvwwxxyzz'";
  154.  
  155. main(argc, argv)  
  156. int argc;
  157. char *argv[];
  158. {
  159.      int n, letters, vowel;
  160.      char name[MAXNAME];
  161.  
  162.      if (argc == 2) {
  163.          /* initialize random number generator */
  164.          srandom(time(0L));
  165.  
  166.          /* generate argv[1] names */
  167.          for (n = atoi(argv[1]); n > 0; n--) {
  168.              name[0] = '\0';
  169.              /* choose whether first character is a vowel */
  170.              vowel =  (rnd(2) ? YES : NO);
  171.              /* get initial character - not " ' " */
  172.              if (vowel)  
  173.                  strncat(name, &vowels[rnd(sizeof(vowels) - 2)], 1);
  174.              else 
  175.                  strncat(name, &cons[rnd(sizeof(cons) - 2)], 1);
  176.              /* upper case first letter */
  177.              name[0] = _toupper(name[0]);
  178.              /* complete rest of letters */
  179.              for (letters = rnd(RANGE) + MINLENGTH; letters > 0; letters--) {
  180.                  /* alternate vowels and consonants */
  181.                  vowel = ( vowel ? NO : YES );
  182.                  /* get next character */
  183.                  if (vowel) 
  184.                      strncat(name, &vowels[rnd(sizeof(vowels)-1)], 1);
  185.                  else 
  186.                      strncat(name, &cons[rnd(sizeof(cons)-1)], 1);
  187.              }
  188.              printf("%s\n", name);
  189.          }
  190.      }
  191.      else 
  192.          printf("Usage: name number-of-names\n");
  193. }
  194.  
  195. //E*O*F name.c//
  196.  
  197. echo x - names.csh
  198. cat > "names.csh" << '//E*O*F names.csh//'
  199. #! /bin/csh
  200. # names - generate random names
  201. #
  202. # usage: names [pages]
  203.  
  204. # bsd script -- uncomment these lines if bsd
  205.  
  206. if ($#argv == 0) then
  207.     name 336 | sort -u | pr -6 | expand
  208. else
  209.     @ n = 336 * $1
  210.     name $n | sort -u | pr -6 | expand
  211. endif
  212.  
  213. # sysv script -- uncomment these lines if sysv
  214. # note: no tab expansion performed
  215.  
  216. #if ($#argv == 0) then
  217. #    name 336 | sort -u | pr -6
  218. #else
  219. #    @ n = 336 * $1
  220. #    name $n | sort -u | pr -6
  221. #endif
  222.  
  223. //E*O*F names.csh//
  224.  
  225. echo x - names.sh
  226. cat > "names.sh" << '//E*O*F names.sh//'
  227. if [ $# = 0 ]
  228. then
  229.     name 336 | sort -u | pr -6
  230. else
  231.     n=`expr 336 \* $1`
  232.     name $n | sort -u | pr -6
  233. fi
  234. //E*O*F names.sh//
  235.  
  236. exit 0
  237.  
  238.