Cross the line
int maze[9][9]; This is the definition. You can visit the maze at most [8][8]. If you cross this line, you are accessing an illegal address outside the array.
-
for(I = 1; I< 10; i++)
{
for(j = 1; j & lt 10; j++)
{
x =(((double)RAND()/(double)RAND _ MAX)* RANGE _ MAX+RANGE _ MIN);
If (x%2)
Labyrinth [i] [j] = 0;
Else maze [i] [j] =1; //randomly generate a maze
}
}
When i=9 and j=9, maze[i][j] crossed the line and must have collapsed.
Besides, there is nothing wrong with the random number itself. Actually, it doesn't have to be so complicated. You can just x = rand () and see if it can be divided by 2. It's a 50% chance anyway. There is another simple way. You can get a random number, multiply it by n times, and directly take its binary form (010100011) as the result. You can get many numbers at a time, and some encryption algorithms get random numbers in this way.
Rand seems to be random, but it is actually based on a mathematical formula. Since it is a formula, there is no absolute randomness. Therefore, if you want to get a large number of random numbers, you must always initialize the random number generator with the time seed. You can do an experiment to see how many times rand starts to repeat (no longer random).