huhulucy90
asked on
How to use rand to generate a four-letter word?
Thanks!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
you can also use 26 instead of 25
ASKER
Thank you all for your help!
I've got the output like:
word = qmzr
I've got the output like:
word = qmzr
ASKER
and I also add a sentence like:
srand(time(NULL));
so get a different output each time.
cheer!
srand(time(NULL));
so get a different output each time.
cheer!
char word[5]="";
....
randomize();
word[0] = random(25) + 1 + 95;
word[1] = random(25) + 1 + 95;
word[2] = random(25) + 1 + 95;
word[3] = random(25) + 1 + 95;
word[4] = '\x0';
printf("word = %s\n", word);
....
btw, inlcude stdlib and time libraries.
magic number 95? thats for lower case
65 for upper case (i think).