### Random Word Generating

Sups :3
So I'm trying to generate a random word though i'm having some issues with it at the moment. I'm using random numbers to them making them.
Here is an example of how i'm trying to do this though its not working.

 ``1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556`` ``````#include #include #include #include #include #include using namespace std; int main() { int randomnumber; char randomword; srand(time(NULL)); for (int loop = 0; loop <= 5; loop++;) { randomnumber = rand() % 5; if (randomnumber == 1) { randomnumber = 0; randomword + 'a'; } if (randomnumber == 2) { randomnumber = 0; randomword + 'b'; } if (randomnumber == 3) { randomnumber = 0; randomword + 'c'; } if (randomnumber == 4) { randomnumber = 0; randomword + 'd'; } if (randomnumber == 4) { randomnumber = 0; randomword + 'e'; } if (randomnumber == 5) { randomnumber = 0; randomword + 'f'; } } cout << randomword; return 0; }``````

I know i'm probably missing something really obvious or stupid.
Thanks
randomnumber = rand() % 5; doesnt have value 5.

Ex: 5005 % 5 = 0
at the begining of the loop add

 ``12`` ``````randomnumber = rand() * 57; randomnumber = rand() % 5;``````

otherwise everytime your loop runs it will generate the same letter. If you multiply your rand() by 57 or any other integer other than 1 or 2, you will take the amount of seconds from your

`srand(time(NULL));`

multiply it by 57 then take the modulus of 5 (which will give you a number 0-4 so i suggest doing (rand() % 5)+1 so it doesnt give you a value of 0 & also take out randomnumber = 0). Now the second time the loop runs you will have a value between 1 and 5. It will take that number and multiply it by 57 then mod 5.

ex.

loop runs once and your number is 3 so it generates a 'c'

second time through you take number * 57 and generate a larger integer and then take % 5 of that integer
Uhm I'm a bit confused do you think you could give me an example of what you mean?
Topic archived. No new replies allowed.