-
Randomization
Will only p1 be randomized or will all the variables (p1,p2,q1,q2.............) be randomized.
Code:
srand((unsigned) time(NULL));
p1 = rand%5;
p2 = rand%5;
q1 = rand%5;
q2 = rand%5;
r1 = rand%5;
r2 = rand%5;
s1 = rand%5;
s2 = rand%5;
t1 = rand%5;
t2 = rand%5;
u1 = rand%5;
u2 = rand%5;
w1 = rand%5;
w2 = rand%5;
-
Tough to answer since you haven't defined rand. If by "rand" you mean to be calling rand() for each variable, then yes, it will be randomized (albeit not necessarily very strongly). If by "rand" you mean to call rand() once and use it as a variable with the same value for each other variable, it will be the same for each usage.
edit: Fixed your code tags for you.
-
A general comment : They are pseudorandomized .
-
My exact question is will the line
srand((unsigned) time(NULL));
effectively randomize the seed values of all of the variables. Or do i have to write this line again and again.
-
You should read this tutorial: Generating Random Numbers in C and C++ - Cprogramming.com
srand() seeds a random number generator. It merely sets up the system to give you random numbers - it doesn't actually generate even a single random number for you. Once you have called srand(), you can call rand() once for every random number you want to generate. So call srand() once no matter what, and then rand() once for each number. Again, in your code it looks like you're trying to use rand as a variable, not a function.