/* version 2 of random person generator. S. Murrell 4th Feb 1998 modify the int variable values just below to suit your needs */ #include #include #include #include int max_name_length=7; int percent_simple_names=20; int percent_named_streets=50; int max_street_name_length=9; int number_of_different_cities=400; int percent_families=17; int max_number_children=2; int percent_families_with_children=50; enum family_member { HUSBAND, WIFE, CHILD, ANY }; /* the following are consonants that may appear at the beginning */ char *bcons[]= {"b","c","ch","d","f","g","h","j","k","l","m","n","p","qu","r","s", "b","c","ch","d","f","g","h","j","k","l","m","n","p","qu","r","s", "sh","t","v","w","y","z", "sc","sk","sl","sm","sn","sp","st", "bl","fl","gl","kl","pl", "br","chr","dr","fr","gr","kr","pr","tr", "bw","dw","fw","gw","tw"}; const int Nbcons=sizeof(bcons)/sizeof(char *); /* the following are consonants that may appear between vowels */ char *mcons[]= {"b","c","ch","ck","d","f","g","h","j","k","l","m","n","p","qu","r","s", "sh","t","v","w","x","y","z", "b","c","ch","ck","d","f","g","h","j","k","l","m","n","p","qu","r","s", "sh","t","v","w","x","y","z", "b","c","ch","ck","d","f","g","h","j","k","l","m","n","p","qu","r","s", "sh","t","v","w","x","y","z", "b","c","ch","ck","d","f","g","h","j","k","l","m","n","p","qu","r","s", "sh","t","v","w","x","y","z", "bb","cc","dd","ff","gg","kk","ll","mm","nn","pp","rr","ss","tt","zz", "mc","md","mf","mg","mk","ml","mn","mp","ms","mt","mv","mz", "nc","nd","nf","ng","nk","nl","np","ns","nt","nv","nz", "sc","sd","sf","sg","sk","sl","sm","sn","sp","st","sv","sz", "mcc","mdd","mff","mgg","mll","mpp","mss","mtt","mzz", "ncc","ndd","nff","ngg","nll","npp","nss","ntt","nzz", "scc","sdd","sff","sgg","sll","smm","snn","spp","stt", "bl","bbl","chl","ckl","dl","ddl","fl","ffl","gl","ggl","kl","pl","ppl","tl","ttl", "br","bbr","chr","ckr","dr","ddr","fr","ffr","gr","ggr","kr","pr","ppr","tr","ttr", "bw","bbw","chw","ckw","dw","ddw","fw","ffw","gw","ggw","kw","pw","ppw","tw","ttw", "llb","llc","llck","llch","lld","llf","llg","llk","llm","lln","llp","llqu","llr","lls", "llt","llv","llw","llx","llz", "lb","lc","lck","lch","ld","lf","lg","lk","lm","ln","lp","lqu","lr","ls", "lt","lv","lw","lx","lz"}; const int Nmcons=sizeof(mcons)/sizeof(char *); /* the following are consonants that may appear at the end */ char *econs[]= {"b","c","ch","ck","d","f","g","h","j","k","l","m","n","p","r","s", "sh","t","v","w","x","y","z", "b","c","ch","ck","d","f","g","h","j","k","l","m","n","p","r","s", "sh","t","v","w", "b","c","ch","ck","d","f","g","h","j","k","l","m","n","p","r","s", "sh","t","v","w", "bb","cc","dd","ff","gg","ll","mm","nn","pp","rr","ss","tt","zz", "md","mg","mk","mn","mp","ms","mt", "nd","ng","nk","ns","nt","nz", "sc","sk","sl","sm","sn","sp","st", "llc","llck","llch","lld","lls", "lc","lck","lch","ld","ls"}; const int Necons=sizeof(econs)/sizeof(char *); /* the following are vowels that may appear at the beginning */ char *bvowl[]= {"a","e","i","o","u","a","e","i","o","u","a", "ai","au","ay","ee", "ia","io","oo"}; const int Nbvowl=sizeof(bvowl)/sizeof(char *); /* the following are vowels that may appear in the middle */ char *mvowl[]= {"a","e","i","o","u","y","a","e","i","o","a","e","ee","a","e","i", "ai","au","ay","ea","ee","ei","eo","eu","ey", "ia","ie","io","iu","oa","oe","oi","oo","ou","oy", "ue","uy"}; const int Nmvowl=sizeof(mvowl)/sizeof(char *); /* the following are vowels that may appear at the end */ char *evowl[]= {"a","e","i","o","u","y", "ai","au","ay","ea","ee","ei","eo","ey", "ia","ie","io","oe","oi","oo","ou","oy", "ue"}; const int Nevowl=sizeof(evowl)/sizeof(char *); /* the following are letters that may appear in simple names */ char *svowl[]={"a","e","i","o","u"}; const int Nsvowl=sizeof(svowl)/sizeof(char *); char *scons[]={"b","c","d","f","g","l","m","n","p","r","s","t"}; const int Nscons=sizeof(scons)/sizeof(char *); char *directions[]={"N","S","W","E","NW","NE","SW","SE"}; const int Ndirections=sizeof(directions)/sizeof(char *); char *roads[]={"Rd","St","Av","Ln","Pl","Ct","Dr","Blvd"}; const int Nroads=sizeof(roads)/sizeof(char *); char *states[]={"ME","NH","VT","MA","RI","CT","NY","NJ","PA","MD", "OH","WV","DE","VA","MI","IN","KY","TN","NC","SC", "MS","AL","GA","FL","LA","AR","MO","IA","MN","ND", "SD","NE","KS","OK","TX","NM","AZ","UT","CO","WY", "MT","ID","NV","CA","OR","WA","AK","HI","WI","IL", "DC","LB","NF","NS","NB","PQ","ON","NT","SK","AB", "BC","YK","MB"}; const int Nstates=sizeof(states)/sizeof(char *); void print_parameters(void) { printf("Current parameters:\n"); printf(" 1: max_name_length = %-5d (2-...)\n",max_name_length); printf(" 2: percent_simple_names = %-5d (0-100)\n",percent_simple_names); printf(" 3: percent_named_streets = %-5d (0-100)\n",percent_named_streets); printf(" 4: max_street_name_length = %-5d (2-...)\n",max_street_name_length); printf(" 5: number_of_different_cities = %-5d (1-98999)\n",number_of_different_cities); printf(" 6: percent_families = %-5d (0-100)\n",percent_families); printf(" 7: max_number_children = %-5d (0-...)\n",max_number_children); printf(" 8: percent_fams_with_children = %-5d (0-100)\n",percent_families_with_children); } void modify_parameter(void) { char line[20]; int pn,n,val; print_parameters(); while (1) { printf("which parameter do you want to modify (1-8 or 0)? "); gets(line); n=sscanf(line,"%d",&pn); if (n!=1 || pn<=0 || pn>8) return; do { printf("enter new value: "); gets(line); n=sscanf(line,"%d",&val); } while (n!=1); switch (pn) { case 1: max_name_length=val; break; case 2: percent_simple_names=val; break; case 3: percent_named_streets=val; break; case 4: max_street_name_length=val; break; case 5: number_of_different_cities=val; break; case 6: percent_families=val; break; case 7: max_number_children=val; break; case 8: percent_families_with_children=val; break; } print_parameters(); } } int skewrand(int maxi) { float v,x; if (maxi<=0) maxi=1; v=((float)(rand()%(200*maxi)))/100.0; x=((float)maxi)*(1.0-sqrt(1.0-v/(2.0*(float)maxi))); return((int)(x+1.0)); } void generate_title(char *title, char *sex, enum family_member who) { int n; do { n=rand()%1000; strcpy(sex,"?"); if (n<11) strcpy(title,"Dr"); else if (n<100 && who!=HUSBAND && who!=WIFE) { strcpy(title,"Miss"); sex[0]='F'; } else if (n<280 && who!=HUSBAND && who!=CHILD) { strcpy(title,"Mrs"); sex[0]='F'; } else if (n<520 && who!=HUSBAND) { strcpy(title,"Ms"); sex[0]='F'; } else if (who!=WIFE) { strcpy(title,"Mr"); sex[0]='M'; } } while (sex[0]=='?'); } void generate_name(char *name) { int len,vow; char *it; len=skewrand(max_name_length/2); vow=rand()%3==0; if (vow) strcpy(name,bvowl[rand()%Nbvowl]); else strcpy(name,bcons[rand()%Nbcons]); vow=!vow; while (1) { if (strlen(name)>14) break; if (len--<=0) break; if (vow) it=mvowl[rand()%Nmvowl]; else it=mcons[rand()%Nmcons]; strcat(name,it); vow=!vow; } if (vow) it=evowl[rand()%Nevowl]; else it=econs[rand()%Necons]; strcat(name,it); name[0]=toupper(name[0]); } void generate_simple_name(char *name, int maxlen, int desirlen, int minlen) { int len,vow; char *it; len=rand()%desirlen; if (lenmaxlen) break; if (len--<=0) break; if (vow) it=svowl[rand()%Nsvowl]; else it=scons[rand()%Nscons]; strcat(name,it); vow=!vow; } name[0]=toupper(name[0]); } void generate_phone_number(char *phone) { const char * const digits="0123456789"; strcpy(phone,"0000000000"); phone[0]=digits[rand()%8+2]; phone[1]=digits[(rand()/7)%2]; phone[2]=digits[rand()%8+2]; phone[3]=digits[rand()%8+2]; phone[4]=digits[rand()%8+2]; phone[5]=digits[rand()%10]; phone[6]=digits[rand()%10]; phone[7]=digits[rand()%10]; phone[8]=digits[rand()%10]; phone[9]=digits[rand()%10]; } void format_phone_number(char *in, char *out) { sprintf(out,"%c%c%c-%c%c%c-%c%c%c%c", in[0],in[1],in[2],in[3],in[4],in[5],in[6],in[7],in[8],in[9]); } void generate_street_address(char *addr) { if ((rand()%100)=Nstates) st=0; if (st<0) st=0; sprintf(zip,"%05d",z); strcpy(state,states[st]); city[0]=0; vow=z%3==0; cvn=z%100; while (z>0) { if (strlen(city)>14) break; if (vow) { x=z%Nsvowl; it=svowl[x]; z=z/(x+1); } else { x=z%Nscons; it=scons[x]; z=z/(x+6); } strcat(city,it); vow=!vow; } city[0]=toupper(city[0]); if (cvn>=0) { if (cvn<25) strcat(city," City"); else if (cvn<40) strcat(city,"ville"); else if (cvn<47) strcat(city,"oria"); else if (cvn<50) strcat(city,"atarium"); else if (cvn<57) strcat(city,"burg"); else if (cvn<62) strcat(city,"ton"); } } int main(int argc, char *argv[]) { int id,famstate,simple_name, maxid; enum family_member person_kind; long int z; char title[5],sex[2],first[100],last[100],ph[15],fph[20], strad[60],city[50],state[3],zip[6]; FILE *script=NULL,*people; srand(time(NULL)); if (argc=2) { maxid=atoi(argv[1])+10001; script=fopen("makepeople","w"); if (script==NULL) { fprintf(stderr,"Can't create \"makepeople\"\n"); exit(1); } people=fopen("people","w"); if (script==NULL) { fprintf(stderr,"Can't create \"people\"\n"); exit(1); } fprintf(script,"create table people\n"); fprintf(script,"( id int,\n"); fprintf(script," sex char(1),\n"); fprintf(script," title char(4),\n"); fprintf(script," fname char(15),\n"); fprintf(script," lname char(15),\n"); fprintf(script," addr char(25),\n"); fprintf(script," city char(20),\n"); fprintf(script," state char(2),\n"); fprintf(script," zip char(5),\n"); fprintf(script," phone char(12));\n"); fprintf(people,"ID____ S TITL FNAME__________ LNAME__________ ADDRESS__________________ " "CITY________________ ST ZIP__ PHONE_______\n"); } else { maxid=1010001; print_parameters(); printf("\nOutput= id#,sex,title,firstname,lastname,streetaddr,city,state,zip,phone\n"); printf(" (families are grouped together, and have same last name & address)\n\n"); } famstate=0; for (id=10001; 1 ; id++) { if (id>=maxid) break; if ((script==NULL) && ((id-10001)%9==0)) { char xxx[20]; printf("\npress ENTER to continue, M to modify parameters, X to exit: "); gets(xxx); if (xxx[0]=='X' || xxx[0]=='x') break; if (xxx[0]=='M' || xxx[0]=='m') modify_parameter(); printf("\n"); } switch (famstate) { case 0: if (rand()%100