How to fill a matrix randomly

0

I have an array filled with the value one in the center, and I want to add new positions with the value 1. These values must be in the boundary dimensions of the array. However, these positions should be changed later until the position reached is next to the initial center position. This should be done until you reach the edge of the array (position 0 or (size-1)).

 x = y = (size + 1) / 2;
   matrix[x][y]=1;                                                          //default of the matrix

   x1=y1=rand()%(size-1);                                                   //random selection of matrix position

   number= switch(rand() %4){
   case 0;
        matrix[x1][0]==1;
        break;
   case 1;
        matrix[size-1][y1]==1;
        break;
   case 2;
        matrix[0][y1]==1;
        break;
   case 3;
        matrix[x1][size-1]==1;
        break
   } 

In this section of the program we have, as defined the position of the center, and how a position is chosen to start filling the matrix. But now there's a question, how do I get the position chosen to be replaced until I'm "neighbor" of a busy position?     

asked by anonymous 15.07.2018 / 21:06

0 answers