Here's a bit of (untested) C code you can toy around with.
#include <stdio.h>//#include <stdlib.h>//#define ST_POWER 0 //#define ST_DEFENSE 1 //#define ST_AGILITY 2 //void main(void){ int Stats[3]; srand(unsigned time (NULL)); //Note //The % (modulo) is used to limit the value of rand, which is //between 0 and 32767 (I think; might be -32767 and 32767. //Maybe someone can validate this...?) // //So, we end up with a number between 0 and 19. The +1 makes it //be between 1 and 20. for(int i = 0; i <= 2; i++) Stats[i] = rand()%20 + 1; printf("Power: %d\n", Stats[ST_POWER ]); printf("Defense: %d\n", Stats[ST_DEFENSE]); printf("Agility: %d\n", Stats[ST_AGILITY]);}
Yes, I use printf();. Bite me.
Like I said, untested, but it should work and if not, well, it should give you a good idea of how rand() and srand() operate. Try setting the parameter for srand() to a constant value like '42' or whatnot and run the program a few times to get the hang of it.
Oh yeah, one more thing... your code indicates only one use of "unsigned" and no actual variable declaration. You should do "unsigned int randomA = ..." etc for every variable otherwise you won't be able to compile without getting the compiler to barf out cryptic stuff like "undeclared identifier" and "do not hit me to make me compiler better".
Edit: the script tags are killing my source. Ignore the blank comment lines in it.
[edited by - RuneLancer on December 5, 2002 9:01:42 PM]