Click here to Skip to main content
15,892,809 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: Random Name Generator Pin
Chuck Vought13-Aug-09 2:11
Chuck Vought13-Aug-09 2:11 
GeneralRe: Random Name Generator Pin
CPallini13-Aug-09 2:31
mveCPallini13-Aug-09 2:31 
GeneralRe: Random Name Generator Pin
Chuck Vought13-Aug-09 3:10
Chuck Vought13-Aug-09 3:10 
General[Message Deleted] Pin
Chuck Vought13-Aug-09 4:17
Chuck Vought13-Aug-09 4:17 
GeneralRe: Random Name Generator Pin
sashoalm13-Aug-09 4:48
sashoalm13-Aug-09 4:48 
GeneralRe: Random Name Generator Pin
Sauce!14-Aug-09 1:04
Sauce!14-Aug-09 1:04 
GeneralRe: Random Name Generator Pin
CPallini17-Aug-09 22:08
mveCPallini17-Aug-09 22:08 
AnswerRe: Random Name Generator PinPopular
Stuart Dootson13-Aug-09 1:01
professionalStuart Dootson13-Aug-09 1:01 
The way I'd approach it is like this:

1. Define functions that return random voewls and random consonants - here's a random vowel function:

char RandomVowel()
{
   const char vowels[] = {'a', 'e', 'i', 'o', 'u'};
   // Use rand() to get a number between 0 and RAND_MAX. Dividing
   // by RAND_MAX+1 gives a number n such that 0 <= n < 1, so
   // multiplying by the number of characters in vowels gives a random
   // index into vowels
   const int index = (int)((double)rand()/(RAND_MAX+1) * sizeof(vowels));
   return vowels[index];
}


2. Build up a string using alternating calls to the random vowel and consonant functions - note that I've remembered about the upper case first character!

std::string name;
name += (char)toupper(RandomConsonant());
for(int i=1;i<desired-name-length;++i)
{
   if (i%2==1)
      name += RandomVowel();
   else
      name += RandomConsonant();
}


Obviously the desired name length should be chosen at random as well!

Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p

AnswerRe: Random Name Generator Pin
sashoalm13-Aug-09 5:16
sashoalm13-Aug-09 5:16 
GeneralRe: Random Name Generator Pin
Chuck Vought13-Aug-09 9:16
Chuck Vought13-Aug-09 9:16 
GeneralRe: Random Name Generator Pin
Chuck Vought13-Aug-09 13:27
Chuck Vought13-Aug-09 13:27 
AnswerRe: Random Name Generator Pin
David Crow14-Aug-09 2:49
David Crow14-Aug-09 2:49 
GeneralRe: Random Name Generator Pin
Chuck Vought14-Aug-09 4:15
Chuck Vought14-Aug-09 4:15 
AnswerRe: Random Name Generator Pin
David Crow14-Aug-09 4:23
David Crow14-Aug-09 4:23 
GeneralRe: Random Name Generator Pin
Chuck Vought14-Aug-09 5:06
Chuck Vought14-Aug-09 5:06 
GeneralRe: Random Name Generator Pin
David Crow14-Aug-09 5:09
David Crow14-Aug-09 5:09 
GeneralRe: Random Name Generator Pin
Chuck Vought14-Aug-09 5:12
Chuck Vought14-Aug-09 5:12 
GeneralRe: Random Name Generator Pin
David Crow14-Aug-09 5:15
David Crow14-Aug-09 5:15 
GeneralRe: Random Name Generator Pin
Chuck Vought14-Aug-09 5:18
Chuck Vought14-Aug-09 5:18 
GeneralRe: Random Name Generator Pin
Chuck Vought14-Aug-09 5:16
Chuck Vought14-Aug-09 5:16 
AnswerRe: Random Name Generator Pin
David Crow14-Aug-09 5:31
David Crow14-Aug-09 5:31 
GeneralRe: Random Name Generator Pin
Chuck Vought14-Aug-09 5:55
Chuck Vought14-Aug-09 5:55 
GeneralRe: Random Name Generator Pin
Chuck Vought14-Aug-09 6:18
Chuck Vought14-Aug-09 6:18 
GeneralRe: Random Name Generator Pin
David Crow14-Aug-09 6:32
David Crow14-Aug-09 6:32 
GeneralRe: Random Name Generator Pin
Chuck Vought14-Aug-09 6:59
Chuck Vought14-Aug-09 6:59 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.