I have a task to do with random numbers . What I have is a rectangular grid of dimension $i \times j$. This grid is subdivided into $ij$ unit boxes $1 \times 1$ each . Say just like this.
Now I have to randomly select these unit boxes such that I gradually increase the number of selected boxes as I move from the top left corner to the bottom right corner . Say something like
Now each pixel is identified by its coordinate $(i,j)$ , how could I write a function or anything which I can control with i , j and say some other parameter to control the density in which as I iterate over i and j : I get whether to select that unit box or not , so that I know that my final pattern is a desired?


If the top left square of the grid is called $(1, 1)$ and the bottom right $(i, j)$ (following standard matrix indexation), then you could say, for instance, that the probability of filling box $(m, n)$ is $$ \frac{m+n}{i+j} $$ This can be tweaked to suit your needs. For instance, this formula guarantees that the bottom right square will be chosen. If you don't like that you can use, for instance, $$ \frac{m+n}{i+j+1} \quad \text{ or }\quad \frac{m+n-1}{i+j} $$ A different approach is $$ p^{m/i}q^{n/j} $$ where $p, q$ are numbers between $0$ and $1$. I am certain that there are many more ways to do it as well.