Thread: Random Name Generator

  1. #1
    Used Registerer jdinger's Avatar
    Join Date
    Feb 2002
    Posts
    1,065

    Random Name Generator

    Here's an example of my random name generator. So far it only
    creates 30 names. When I finally release the beta for my game it
    will create 100. You only get 5 troops from a choice of 15, so
    there is a very good chance of getting a unique squad with each
    new game (the game is designed to provide long gameplay, so
    you'll not likely be starting a ton of new games anyway, but
    advancing a saved game).

    I'm using the same algorithms to generate random skills and
    attributes for each trooper. So you and nine of your friends could
    all start new games and get 10 original, unique sets of troops.

    Let me know what you think.

  2. #2
    Used Registerer jdinger's Avatar
    Join Date
    Feb 2002
    Posts
    1,065
    OK, for some strange reason the attachment didn't work?

    Attempt #2:

  3. #3
    Registered User blight2c's Avatar
    Join Date
    Mar 2002
    Posts
    266
    any chance i can see the code, i wouldn't understand the windows stuff, but just the funciton

    it's cool though . . it does what it's suppose to. i'll be more impressed if i can see the code i mean

  4. #4
    Pygmy Monkey ErionD's Avatar
    Join Date
    Feb 2002
    Posts
    408
    Hehe i got a guy named Mark Marks =)
    Anyway, its really cool!

  5. #5
    Used Registerer jdinger's Avatar
    Join Date
    Feb 2002
    Posts
    1,065
    any chance i can see the code, i wouldn't understand
    the windows stuff, but just the funciton
    Sure. Here's the code with added comments leaving out most of
    the windows only stuff:

    Code:
    //in the global declares
     //the cName struct, simply used to hold a name segment and 
     //has a flag to show if it's already been used.
    struct cName
    {
        char cNameSeg[40];
        bool bUsed;
    };
    
     //need 3 of these, 1 for list of first names, 1 for list of last names
     //and 1 for the amalgamated full names
    cName fName[30], lName[30], wName[30];
    
    int iRand, iName;
    
    void GetRandNames()
    {
       //reset the bUsed flags and empty the list of whole names
       for(int i=0;i<30;i++)
       {
          fName[i].bUsed=false;
          lName[i].bUsed=false;
          wName[i].bUsed=false;
          strcpy(wName[i].cNameSeg,"");
       }
     
       //fill the cNameSeg members with data
       strcpy(fName[0].cNameSeg,"Jason");
       strcpy(fName[1].cNameSeg,"Bill");
       //etc. etc. etc.
        //currently this is a long list of strcpy's. today I'm modifying it
        //so that it writes the 200 structs (100 fName, 100 lName) to
        //a file and then reads them back in at run-time.
    
       //reset the whole name counter
       iName=0;
       //randomize based on time
       srand((unsigned)time(NULL));
       
       //cycle through setting the first name values randomly into the
       //whole name structs   
       for(int iFN=0;iFN<3000;iFN++)
       {
          iRand=rand()%30;
          if(!fName[iRand].bUsed)
         {
            fName[iRand].bUsed=true;
            strcpy(wName[iName].cNameSeg,fName[iRand].cNameSeg);
            iName++;
         }
       }
    
        //reset the name counter
        iName=0;
      
       //do the same for the last names, concatenating them with
      //the first names
      for(int iLN=0;iLN<3000;iLN++)
      {
         iRand=rand()%30;
         if(!lName[iRand].bUsed)
         {
            lName[iRand].bUsed=true;
            strcat(wName[iName].cNameSeg," ");
            strcat(wName[iName].cNameSeg,lName[iRand].cNameSeg);
            iName++;
          }
        }
    }
    Pretty straightforward. No real window's specific stuff in the
    function itself. So, it could easily be used to generate names for
    console app RPG's, etc..

  6. #6
    Used Registerer jdinger's Avatar
    Join Date
    Feb 2002
    Posts
    1,065
    Originally posted by ErionD
    Hehe i got a guy named Mark Marks =)
    Anyway, its really cool!
    With the additional names I've already added I've gotten a few
    really unique names:

    *some examples*
    Tyrone Hirihito
    Willy Williams
    Bob Robertson
    Jaques Davenport
    Kareem Gonzalez

  7. #7
    Unregistered
    Guest
    cool!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How exactly does the random number generator work?
    By Finchie_88 in forum C++ Programming
    Replies: 6
    Last Post: 08-24-2007, 12:46 AM
  2. NAQ: Everything you never wanted to know about CPP
    By evildave in forum C Programming
    Replies: 21
    Last Post: 12-12-2005, 10:56 AM
  3. Testing Random Number Generator
    By Roaring_Tiger in forum C Programming
    Replies: 7
    Last Post: 08-12-2005, 12:48 AM
  4. Random character generator algorithm
    By m712 in forum C++ Programming
    Replies: 7
    Last Post: 12-09-2002, 04:28 AM
  5. Random number generator
    By Caze in forum C++ Programming
    Replies: 6
    Last Post: 12-03-2002, 08:10 AM