How to sample cells of a grid (matrix) according to a Normal(Gaussian) distribution?
<p>I need to sample cells of a grid (matrix of MXN) according to a Normal Distribution in Java.</p>

<p>I know that <a href="http://commons.apache.org/proper/commons-math/userguide/distribution.html" rel="nofollow">the Apache Math library</a> has functions to sample values unidimensionally (1D), so it would be fine for a vector but I cannot find any alternative for 2D.</p>

<p>I have thought in using the 1D approach twice: one for rows, and another for cols. However, (1) it is not exactly appropiate since it would be using <a href="https://en.wikipedia.org/wiki/Von_Neumann_neighborhood" rel="nofollow">Von Neumann distances</a> and not the <a href="https://en.wikipedia.org/wiki/Distance#Geometry" rel="nofollow">geometrical distance</a>, and (2) this approach would not avoid repetitions (i.e. it wouldn't be sampling).</p>

<p>So, how do I sample cells of a grid (matrix) according to a Normal(Gaussian) distribution centered in particular cell(r,c)?</p>

<hr>

<p><strong><em>Alternatively</em></strong>, if sampling is not possible (or too complicated), how I do distribute the probability using a Normal distribution accross cells in a grid centered in particular cell(r,c)? For example, for 3x3::</p>

<pre><code>0.1 | 0.1 | 0.1
0.1 | 0.2 | 0.1
0.1 | 0.1 | 0.1
</code></pre>

<p>I am not sure if the previous values would actually fit any Gaussian, but more importantly, for any matrix, the sum of the cell has to be 1.</p>

<p>From here I can just iterate, and roll for it; or roll and iterate adding up.</p>