home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Usenet 1994 October
/
usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso
/
misc
/
volume9
/
rndname3
/
name.c
< prev
next >
Wrap
C/C++ Source or Header
|
1989-11-08
|
4KB
|
115 lines
/**************************************************************************
* name - prints random names *
* Copyright 1988, 1989 by Brett Slocum. All rights reserved. *
* Permission is granted to distribute, modify, or use portions of this *
* code in other programs, as long as this notice remains intact. *
* This program or its derivatives may not be sold for profit without *
* permission. *
* *
* UNIX Version: Brett Slocum UUCP: ...uunet!hi-csc!slocum *
* ARPA: slocum@hi-csc.honeywell.com *
* Changes were suggested by Geoff Kimbrough <geoff@ism780c.isc.com> *
* *
* IBM Microsoft C v5.0 changes by Loyd Blankenship on 11-15-88 *
* UUCP: ...rutgers.edu!cs.utexas.edu!nth!loyd *
* *
* Version 2 by Brett Slocum 3/22/89 : various cleanups, features, etc. *
* *
* Version 3 by Brett Slocum 11/7/89 : Scrabble (tm) letter distribution *
* *
**************************************************************************/
#ifdef SYSV
#include <string.h>
#define srandom srand48
#define random lrand48
#endif
#ifdef BSD
#include <strings.h>
#endif
#ifdef MSC
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define srandom srand
#define random rand
#endif
#include <ctype.h>
#define YES 1
#define NO 0
#define MAXNAME 30
#define MINLENGTH 3
#define RANGE 6
#define rnd(n) (unsigned)(random() % (n))
/*
Since "y" appears twice, once in each string; all other
letters, except "'", are doubled to keep the distribution even.
By adding or deleting the letters from these strings, you
can change the frequency of appearance of the letters,
(i.e. by adding an "e" and a "t" and deleting a "z" and a "q",
a distribution closer to English could be made.)
Another set of strings has the Scrabble (tm) distributions of letters.
Put -DSCRABBLE into the Makefile, if you want the Scrabble (tm) distribution.
*/
#define FLAT_VOWELS "aaeeiioouuy'"
#define FLAT_CONS "bbccddffgghhjjkkllmmnnppqqrrssttvvwwxxyzz'"
#define SCRABBLE_VOWELS "aaaaaaaaaeeeeeeeeeeeeiiiiiiiiioooooooouuuuy'"
#define SCRABBLE_CONS "bbccddddffggghhjkllllmmnnnnnnppqrrrrrrssssttttttvvwwxyz'"
#ifdef SCRABBLE
char vowels[] = SCRABBLE_VOWELS;
char cons[] = SCRABBLE_CONS;
#else
char vowels[] = FLAT_VOWELS;
char cons[] = FLAT_CONS;
#endif
main(argc, argv)
int argc;
char *argv[];
{
int n, letters, vowel;
char name[MAXNAME];
if (argc == 2) {
/* initialize random number generator */
srandom(time(0L));
/* generate argv[1] names */
for (n = atoi(argv[1]); n > 0; n--) {
name[0] = '\0';
/* choose whether first character is a vowel */
vowel = (rnd(2) ? YES : NO);
/* get initial character - not " ' " */
if (vowel)
strncat(name, &vowels[rnd(sizeof(vowels) - 2)], 1);
else
strncat(name, &cons[rnd(sizeof(cons) - 2)], 1);
/* upper case first letter */
name[0] = _toupper(name[0]);
/* complete rest of letters */
for (letters = rnd(RANGE) + MINLENGTH; letters > 0; letters--) {
/* alternate vowels and consonants */
vowel = ( vowel ? NO : YES );
/* get next character */
if (vowel)
strncat(name, &vowels[rnd(sizeof(vowels)-1)], 1);
else
strncat(name, &cons[rnd(sizeof(cons)-1)], 1);
}
printf("%s\n", name);
}
}
else
printf("Usage: name number-of-names\n");
}