how to fill elements of adjacents cells of a 4x4 table?

hi! we are making a 4x4 table and need to insert the data in its adjacent cell. we are able to get the adjacent cells but when we are putting the element on each cell, not all cells have content. there is only 1-3 cells with element. how can we solve this problem? thanks in advance :slight_smile:

here is our code.

//first random position
System.Random rnd = new System.Random();
int initA = rnd.Next(1, 4);
int initB = rnd.Next(1, 4);
Debug.Log(β€œ[” + initA + β€œ,” + initB + β€œ]”);

    // getting neighbors and adding elements
    int[,] adder =  {{-1,-1},{-1,0},{-1,1},
                     {0,-1},      {0,1},
                     {1,-1},{1,0},{1,1}};

    int neighborRow = initA, neighborCol = initB;
    Debug.Log("adder Length: " + adder.Length + " tilegrid length: "+ tileGrid.Length);
    for (int i = 0; i < binDigits.Length; i++)
    {
        int curRow = neighborRow, curCol = neighborCol;

        neighborRow = neighborRow+ adder[i, 0];
        neighborCol = neighborCol + adder[i, 1];
        Debug.Log(i);

        while (neighborRow < 0 || neighborCol < 0  || neighborRow >= 4 || neighborCol >= 4 || isFilled[neighborRow, neighborCol] != false)
        {
            int curRnd = Random.Range(0, 8);
            neighborRow = curRow + adder[curRnd, 0];
            neighborCol = curCol + adder[curRnd, 1];
        }
        Debug.Log("neighbors: [" + neighborRow + "," + neighborCol + "]");

        isFilled[neighborRow, neighborCol] = true;
        Debug.Log("isFilled? " + isFilled[neighborRow, neighborCol]);

        tileGrid[neighborRow, neighborCol] = binDigits*.ToString();*

Debug.Log(β€œContent{ " + tileGrid[neighborRow, neighborCol] + " }”);

}

binDigits is an array containing the elements to be put in the tileGrid. Thanks!