2 Replies - 23061 Views - Last Post: 26 October 2006 - 07:44 PM Rate Topic: -----

#1 ifoam  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 54
  • Joined: 26-October 06

Random Word Generator

Posted 26 October 2006 - 05:45 PM

I'm trying to figure out how to generate random words. They don't need to make sense. For instance: it can generate "dfgag" "sge" sdvbsvdv". It would be perferable to make it generate less than 7 chars.

I've tried looking online but I can't find anyone who has done this.

Does anyone have a function, a place online, or even pseudo code that can point me in the right direction?
Is This A Good Question/Topic? 0
  • +

Replies To: Random Word Generator

#2 Amadeus  Icon User is offline

  • g+ + -o drink whiskey.cpp
  • member icon

Reputation: 248
  • View blog
  • Posts: 13,506
  • Joined: 12-July 02

Re: Random Word Generator

Posted 26 October 2006 - 07:28 PM

One suggestion would be to generate a random number between 2 and 7 (the length of the word), then, for that number of letters, generate a random number between 1 and 26. Take that letter of the alphabet and repeat.
Was This Post Helpful? 0
  • +
  • -

#6 ifoam  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 54
  • Joined: 26-October 06

Re: Random Word Generator

Posted 26 October 2006 - 07:44 PM

Someone helped me with this:


void rword (char *word)
{
int len = rand () % 6 + 1;
word [len] = 0;
while (len) word [--len] = 'a' + rand () % 26;
}

int main ()
{
	char word[7];
	char word2[7];
	int x=0;
	srand(time(0));
	while (x<500000) 
	{
	  rword(word);
	  rword(word2);
	  cout << word << ' ' << word2 << endl; 
	  //printf ("%s\n", word);
	  x++;
	}
}




it works pretty good. it generates 499999 "full names" in under a minute
Was This Post Helpful? 1

Page 1 of 1