How to add elements into a randomly position of a 2d array/matrix?
<p>Hey I was trying to add elements on random position of a matrix a[3][3];
The problem is that when it remains 2-3 free position on the matrix, the program crashes. Refuses to get out of the while loop.</p>

<pre><code>char a[3][3]={{ '.' , '.' , '.' },{ '.' , '.' , '.' },{ '.' , '.' , '.' }};
if(selected!=true&amp;&amp;postpone!=true&amp;&amp;elemctr&lt;8)
    {
        Orow=rand()%3;
        Ocol=rand()%3;
        while(1)
        {
            cout &lt;&lt; "in while";
            cout &lt;&lt; endl;

        if(a[Orow][Ocol]=='.')
            {
                if(Orow!=Xrow||Ocol!=Xcol)
                {
                    fct();
                    ocalled=true;
                }   
            }

        else
            {
                //-------------------
                for(int i=0;i&lt;3;i++)
                {
                    for (int j=0;j&lt;3;j++)
                    {
                        if(a[i][j]=='.')
                        {
                            Orow=i;
                            Ocol=j;
                            found=true;
                            break;
                        }
                        if(found==true)
                        {
                            break;
                        }

                    }
                    if(found==true)
                    {
                        break;
                    }   
                }
            }
            if(ocalled==true)
            {
                break;
            }
        }
}
</code></pre>

<p>What to do, to avoid being stuck in the while loop, and to complete all the matrix position taken randomly with a certain element?</p>