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..