Hey guys
I am writing a very simple game of war and my random output seem's a bit bizzare. Code will explain it better.
Code:
// computer's turn to choose its leigons
unsigned short compFoot = 1 + rand() % 50;
unsigned short compFly = 1 + rand() % 50;
unsigned short compHse = 1 + rand() % 50;
unsigned short compAgt = 1 + rand() % 50;
Which is fine - I always get a random unit number for each leigon when I run the program.
Now, the problem comes when I do this:
Code:
short defeatedCmpFoot = 1 + rand() % compFoot;
To choose how many of that unit have been defeated, I either get to more than the chosen number in the first peice of code I posted or I repeatedly get the same number for every single unit being defeated.
I do have
Code:
srand((unsigned)time(0));
At the start - but I cannot figure out what is going wrong with the random number choice. Everything else works fine and the game runs through ok but I am obviously getting invalid results at the end due to the random number.
Can sombody give me any pointers? Any help appreiciated!