Okay, I tried printing my values, and I did discover that
pos
is actually 0 every time, not 1.. oops. But I was still getting the same number for
pos
every time. Then I tried adding this code to the part where I'm generating the two random numbers:
1 2 3 4 5 6 7 8

for (int i = 0; i < 20; i++)
{
pos = rand() % 7;
form = rand() % 5;
cout << "pos = " << pos << "\t";
cout << "form = " << form << endl;
}
 
Here's what I got:
pos = 0 form = 4
pos = 4 form = 0
pos = 1 form = 0
pos = 3 form = 4
pos = 6 form = 1
pos = 3 form = 2
pos = 0 form = 2
pos = 4 form = 2
pos = 0 form = 0
pos = 3 form = 3
pos = 0 form = 1
pos = 6 form = 3
pos = 3 form = 2
pos = 5 form = 3
pos = 0 form = 3
pos = 4 form = 4
pos = 4 form = 3
pos = 2 form = 2
pos = 3 form = 1
pos = 6 form = 1
Seems pretty random, right? But then I ran it again several times, and every time, the first value for
pos
was always 0. Like, at least a dozen times. But this only happens with
pos
, not with
form
. It seems that any time I use
rand()%7
, the first number I get is always 0. It doesn't happen with
rand()%5
or any other random number generator as far as I can tell.
So any time I need a number between 0 and 6, I guess I'll have to call rand() twice and use the second value. But I shouldn't have to do this, right?
And btw, I'm definitely not running my program more than once in the same second.
UPDATE: I just tried changing my code to this:
1 2 3 4 5 6 7 8

for (int i = 0; i < 20; i++)
{
form = rand() % 5;
pos = rand() % 7;
cout << "pos = " << pos << "\t";
cout << "form = " << form << endl;
}
 
All I did was switch lines 3 and 4. Now the first number isn't 0 every time any more. So weird. I have no idea why that would make a difference.