Hi all. I'm writing a program to explain and verify the birthday paradox. I am generating 1000 sets (only 10 to test with) of birthdays, checking for matches, then displaying the results. I'm using srand to seed my generator and rand() to get 23 sets. The problem is 2-fold. 1) It's generating a series of identical negative numbers at the start of the first run. I thought unsigned int was supposed to prevent negatives? 2) It's generating identical sets of numbers. After the first set, there are no more negative numbers but each set is identical. I don't know if this is a matter of generating the sets faster than my clock advances, or if I did something wrong. I've scoured the web and it "looks" like I have it coded correctly.
srand((unsigned int) time (0));
This is in main() after my variable declarations. I only have one call to it.
void GenerateBirthdays(int B[], int SS, int &M)
{
int j = 0; //j is loop counter, M is # of Matches
for (int i = 0; i < NUMBER_OF_SETS; ++i)
{
while (B[j] < SS)
{
B[j] = 1 + (rand() % 365);
++j;
cout << B[j] << endl;
}
SelectionSort(B, SS);
for (j = 0; B[j] < SS; ++j)
{
if (B[j] == B[j+1])
++M;
cout << M << endl;
}
}
}
This is my function call. My sort function works correctly. My match counter doesn't, but that's something I'll worry about later. If it makes a difference, I'm using a switch statement to create a menu. It also won't let me exit the program without a Run-Time Check Error #2- Stack around the variable 'Birthdays' was corrupted. I'm hoping fixing my srand issue will fix the run time error as well.