English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

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?

2006-10-26 13:49:21 · 3 answers · asked by ifoam 3 in Computers & Internet Programming & Design

3 answers

#include
#include

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

int main ()
{
char word[7];
srand(time(0));
while (1) {rword(word); printf ("%s\n", word);}
}

2006-10-26 15:18:29 · answer #1 · answered by n0body 4 · 1 0

right it rather is the code: #contain #contain #contain /* prints a random huge style interior the style 0 to ninety 9 */ int important(void) { randomize(); printf("Random huge style interior the 0-ninety 9 variety: %dn", random (one hundred)); return 0; }

2016-12-28 05:56:16 · answer #2 · answered by purinton 3 · 0 0

I would strongly encourage you to take a good C++ course or follow some tutorials.

#include
#include
#include


static short getRandomNbr(short low, short high)
{
return(low + (short) ((double)(1 + high - low) * ((double)rand() / 100.0) / ((double)RAND_MAX / 100.0)));
} /* getRandomNbr() */


main()
{
register short i;
unsigned char answer[8];
unsigned int luck; // :)

memset(answer, 0, 8);

srand((unsigned int)(time((time_t *) 0)));

usleep((luck = 1000 + 80 * getRandomNbr(1, 10000)));

srand((unsigned int)(time((time_t *) 0)) + luck);

for (i = 0; i < getRandomNbr(1, 7); i ++)
{
answer[i] = (unsigned char) getRandomNbr((short)'a', (short)'z');
} // for

printf("%s\n", answer);

} // main()

2006-10-26 15:31:46 · answer #3 · answered by juliepelletier 7 · 0 1

fedest.com, questions and answers