www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2000/12/30/14:57:19

From: "neohashi" <Neohashi AT mail DOT tele DOT dk>
Newsgroups: comp.os.msdos.djgpp
Subject: small problem with namegenerator.
Date: Sat, 30 Dec 2000 20:47:33 +0100
Organization: Posted Courtesy of Tele Danmark or one of its European Subsidiaries
Lines: 59
Message-ID: <92ldqa$300$1@news.inet.tele.dk>
NNTP-Posting-Host: ip50.odnxr5.ras.tele.dk
X-Trace: news.inet.tele.dk 978205322 3072 195.215.234.50
X-Complaints-To: the appropriate department of the poster's provider
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 5.50.4133.2400
X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4133.2400
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

Hi to all,

I am trying to make a random name generator, but thou they are random, all
2000 names ends up the same... what is wrong here??

note:
srandom(time(NULL));  _is_ called before the function below.
just ignore the global header... it is just used to get access to the city
array.

#include <time.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>

#include "global.h"


void set_names(void)
{
 int ran,n;
 char *n1,*n2,*n3,finalname[11];

 for(n=0;n<2000;n++)
 {
      ran = (random()%10);

      if(ran <= 5)
         n2 = "ka";
      else
         n2 = "cona";

      ran = (random()%10);

      if(ran <= 5)
         n2 = "tha";
      else
         n2 = "gnu";

      ran = (random()%10);

      if(ran <= 5)
         n3 = "so";
      else
         n3 = "dom";

      sprintf(finalname,"%s%s%s",n1,n2,n3);

      strcpy(city[n].name,finalname);
   }
}


TIA

/neohashi



- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019