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

  1. From decwrl!purdue!mailrus!ncar!tank!nic.MR.NET!hal!ncoast!allbery Sun Nov 13 00:43:42 PST 1988
  2. Article 715 of comp.sources.misc:
  3. Path: granite!decwrl!purdue!mailrus!ncar!tank!nic.MR.NET!hal!ncoast!allbery
  4. From: slocum@hi-csc.UUCP (Brett Slocum)
  5. Newsgroups: comp.sources.misc
  6. Subject: v05i039: Random Name Generator Source Code
  7. Summary: name generator for RPG games
  8. Message-ID: <3f6d7ec2.805@hi-csc.UUCP>
  9. Date: 9 Nov 88 02:21:39 GMT
  10. Sender: allbery@ncoast.UUCP
  11. Reply-To: slocum@hi-csc.UUCP (Brett Slocum)
  12. Organization: csdd
  13. Lines: 208
  14. Approved: allbery@ncoast.UUCP
  15.  
  16. Posting-number: Volume 5, Issue 39
  17. Submitted-by: "Brett Slocum" <slocum@hi-csc.UUCP>
  18. Archive-name: rnameg
  19.  
  20. [Looks reasonably portable to BSD or System V, but wants one of the better
  21. random number generators.  ++bsa]
  22.  
  23. This program is a very simple random name generator that produces
  24. surprisingly good names.  They tend to be exotic, since 'X' and 
  25. 'Z' have the same chance of coming up as 'T' and 'N'.  Many of the
  26. names have a Japanese or African flavor.  Some of my favorites
  27. came in the first page: Zozaras, Lyxam, Rux, and Zelica.
  28.  
  29. The program 'name.c' produces the names, and two scripts are 
  30. included to formats them into pages: names.csh and names.sh, 
  31. for C-shell and Bourne shell, respectively.
  32.  
  33. These programs have been tested on an Apollo DN330 with both
  34. BSD4.2 and Sys V, and on BSD4.3.  The makefile and names.csh 
  35. script have Sys V versions commented out.
  36.  
  37. Send any changes or updates to me:
  38.  
  39. Brett Slocum
  40. ...uunet!hi-csc!slocum
  41. slocum@hi-csc.honeywell.com
  42.  
  43. P.S. Thanks to Geoff Kimbrough <geoff@ism780c.isc.com> for
  44. suggesting some improvements.
  45.  
  46. #--------------------------------CUT HERE-------------------------------------
  47. #! /bin/sh
  48. #
  49. # This is a shell archive.  Save this into a file, edit it
  50. # and delete all lines above this comment.  Then give this
  51. # file to sh by executing the command "sh file".  The files
  52. # will be extracted into the current directory owned by
  53. # you with default permissions.
  54. #
  55. # The files contained herein are:
  56. #
  57. # \c
  58. -rwxrwx---  1 slocum        251 Nov  2 09:15 Makefile
  59. # \c
  60. -rwxrwx---  1 slocum        451 Nov  2 09:15 names.csh
  61. # \c
  62. -rwxrwx---  1 slocum        111 Nov  2 09:15 names.sh
  63. # \c
  64. -rwxrwx---  1 slocum       2545 Nov  2 09:15 name.c
  65. #
  66. echo 'x - Makefile'
  67. if test -f Makefile; then echo 'shar: not overwriting Makefile'; else
  68. sed 's/^X//' << '________This_Is_The_END________' > Makefile
  69. X#  makefile for name.c
  70. X#
  71. X#       Comment out the BSD line if you're on System V
  72. X#       Comment out the SYSV line if you're using Berkely Unix.
  73. X# SYSTEM = -DSYSV 
  74. XSYSTEM = -DBSD
  75. XCFLAGS = -O $(SYSTEM)
  76. Xname:   name.c
  77. X    cc -o name $(CFLAGS) name.c
  78. X
  79. ________This_Is_The_END________
  80. if test `wc -l < Makefile` -ne 13; then
  81.     echo 'shar: Makefile was damaged during transit (should have been 13 bytes)'
  82. fi
  83. fi        ; : end of overwriting check
  84. echo 'x - names.csh'
  85. if test -f names.csh; then echo 'shar: not overwriting names.csh'; else
  86. sed 's/^X//' << '________This_Is_The_END________' > names.csh
  87. X#! /bin/csh
  88. X# names - generate random names
  89. X#
  90. X# usage: names [pages]
  91. X
  92. X# bsd script -- uncomment these lines if bsd
  93. X
  94. Xif ($#argv == 0) then
  95. X    name 336 | sort -u | pr -6 | expand
  96. Xelse
  97. X    @ n = 336 * $1
  98. X    name $n | sort -u | pr -6 | expand
  99. Xendif
  100. X
  101. X# sysv script -- uncomment these lines if sysv
  102. X# note: no tab expansion performed
  103. X
  104. X#if ($#argv == 0) then
  105. X#    name 336 | sort -u | pr -6
  106. X#else
  107. X#    @ n = 336 * $1
  108. X#    name $n | sort -u | pr -6
  109. X#endif
  110. X
  111. ________This_Is_The_END________
  112. if test `wc -l < names.csh` -ne 24; then
  113.     echo 'shar: names.csh was damaged during transit (should have been 24 bytes)'
  114. fi
  115. fi        ; : end of overwriting check
  116. echo 'x - names.sh'
  117. if test -f names.sh; then echo 'shar: not overwriting names.sh'; else
  118. sed 's/^X//' << '________This_Is_The_END________' > names.sh
  119. Xif [ $# = 0 ]
  120. Xthen
  121. X    name 336 | sort -u | pr -6
  122. Xelse
  123. X    n=`expr 336 \* $1`
  124. X    name $n | sort -u | pr -6
  125. Xfi
  126. ________This_Is_The_END________
  127. if test `wc -l < names.sh` -ne 7; then
  128.     echo 'shar: names.sh was damaged during transit (should have been 7 bytes)'
  129. fi
  130. fi        ; : end of overwriting check
  131. echo 'x - name.c'
  132. if test -f name.c; then echo 'shar: not overwriting name.c'; else
  133. sed 's/^X//' << '________This_Is_The_END________' > name.c
  134. X/**************************************************************************
  135. X *      name - prints random names                                        * 
  136. X *  Copyright 1988 by Brett Slocum.  All rights reserved.                 *
  137. X *  Permission is granted to distribute, modify, or use portions of this  *
  138. X *  code in other programs, as long as this copyright notice remains      *
  139. X *  intact.  This program may not be sold for profit without permission.  *
  140. X *                                                                        *
  141. X *  Changes were suggested by Geoff Kimbrough <geoff@ism780c.isc.com>     *
  142. X **************************************************************************/
  143. X
  144. X#ifdef SYSV
  145. X#include <string.h>
  146. X#define srandom srand48
  147. X#define random lrand48
  148. X#else
  149. X#include <strings.h>
  150. X#endif
  151. X
  152. X#include <ctype.h>
  153. X
  154. X#define YES 1
  155. X#define NO 0
  156. X#define MAXNAME 30
  157. X#define MINLENGTH 3
  158. X#define RANGE 6
  159. X#define rnd(n) ((unsigned) random() % (unsigned) n)
  160. X
  161. X/* Since "y" and "'" appear twice, once in each array, all other 
  162. X   letters are doubled to keep the distribution even. */
  163. X
  164. X char vowels[] = "aaeeiioouuy'";
  165. X char cons[] = "bbccddffgghhjjkkllmmnnppqqrrssttvvwwxxyzz'";
  166. X
  167. Xmain(argc, argv)  
  168. Xint argc;
  169. Xchar *argv[];
  170. X{
  171. X     int n, letters, vowel;
  172. X     char name[MAXNAME];
  173. X
  174. X     if (argc == 2) {
  175. X         /* initialize random number generator */
  176. X         srandom(time(0L));
  177. X
  178. X         /* generate argv[1] names */
  179. X         for (n = atoi(argv[1]); n > 0; n--) {
  180. X             name[0] = '\0';
  181. X             /* choose whether first character is a vowel */
  182. X             vowel =  (rnd(2) ? YES : NO);
  183. X             /* get initial character - not " ' " */
  184. X             if (vowel)  
  185. X                 strncat(name, &vowels[rnd(sizeof(vowels)-2)], 1);
  186. X             else 
  187. X                 strncat(name, &cons[rnd(sizeof(cons)-2)], 1);
  188. X             /* upper case first letter */
  189. X             name[0] = _toupper(name[0]);
  190. X             /* complete rest of letters */
  191. X             for (letters = rnd(RANGE) + MINLENGTH; letters > 0; letters--) {
  192. X                 /* alternate vowels and consonants */
  193. X                 vowel = ( vowel ? NO : YES );
  194. X                 /* get next character */
  195. X                 if (vowel) 
  196. X                     strncat(name, &vowels[rnd(sizeof(vowels))], 1);
  197. X                 else 
  198. X                     strncat(name, &cons[rnd(sizeof(cons))], 1);
  199. X             }
  200. X             printf("%s\n", name);
  201. X         }
  202. X     }
  203. X     else 
  204. X         usage();
  205. X}
  206. X
  207. Xusage()  /* print usage statement */
  208. X{
  209. X     printf("Usage: name number-of-names\n");
  210. X}
  211. ________This_Is_The_END________
  212. if test `wc -l < name.c` -ne 77; then
  213.     echo 'shar: name.c was damaged during transit (should have been 77 bytes)'
  214. fi
  215. fi        ; : end of overwriting check
  216. exit 0
  217. -- 
  218. Brett Slocum   UUCP: ...uunet!hi-csc!slocum
  219.                Arpa: slocum@hi-csc.honeywell.com
  220. "My name is Inigo Montoya. You killed my father. Prepare to die."
  221.  
  222.  
  223.