home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / compsrcs / misc / volume06 / rndname < prev    next >
Encoding:
Internet Message Format  |  1991-08-27  |  8.0 KB

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