How to fill in [x]% of a 2d array with the values of another array : <p>I have 2 two-dimensional arrays, one is filled and one is to be filled, both of the same size (n x m). I need to fill in [some random]% of my second array with the exact same values as my first array.
So let's say</p>

<pre><code>int[][] arr1 = new int[][] {{0, 1, 0, 1},
                            {1, 0, 1, 0},
                            {0, 0, 1, 1},
                            {1, 1, 0, 0}};
</code></pre>

<p>I want arr2 to be filled with 25% of arr1's values in the same spot with the other spots just remaining null..</p>

<pre><code>int[][] arr2 = new int[4][4];
// where arr2 = something like {{0,1,0,1},
//                              { , , , },
//                              { , , , },
//                              { , , , }}
</code></pre>

<p>Eventually, the program will call on the user to fill in the missing values, which I can do, just for some reason this part seems to not want to work for me.
This is for a school assignment and the teacher isn't being very helpful with answering questions.</p>

<p>Here's my code:
noting that (variable names are in French..)</p>

<ol>
<li>nbCases = total number of elements in the 2d array</li>
<li>nbARemplir = number of elements in the 2nd array to have values assigned to them (based on nbCases * nbPourc where nbPourc is the percentage of the 2nd array to be assigned values)</li>
<li>grille[][] = original array</li>
<li><p>gui = second "array" (it's actually a 2d array of JButtons that the teacher wrote..syntax to add a value : gui.setValeur(i, j, value) )</p>

<pre><code>int nbCases = grille.length * grille[0].length;
int nbARemplir = (int)(nbCases * nbPourc);

do{
    for(int i = 0; i &lt; grille.length; i++) {
        for(int j = 0; j &lt; grille[i].length; j++) {
            if(rand.nextInt(2) == 1 &amp;&amp; nbARemplir &gt; 0) {
                gui.setValeur(i, j, "" + grille[i][j]);
                nbARemplir--;
            }
        }
    }       
} while(nbARemplir &gt; 0);
</code></pre></li>
</ol>

<p>Thanks for your help! :)</p>
