I am writing a very simple game of war and my random output seem's a bit bizzare. Code will explain it better.
Which is fine - I always get a random unit number for each leigon when I run the program.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;
Now, the problem comes when I do this:
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.Code:short defeatedCmpFoot = 1 + rand() % compFoot;
I do have
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.Code:srand((unsigned)time(0));
Can sombody give me any pointers? Any help appreiciated!