Take an $n \times n$ random matrix whose entries are i.i.d. with uniform distribution in $[0,1]$. Look at the sums of the elements of each row and then permute the rows so that these sums form an increasing sequence. Next, perform the analogous sorting of the columns.


*Obvious remarks:* Almost surely no two rows or columns will have the same sum and so the double-sorting operation is uniquely defined. Moreover, the operation is symmetrical: it makes no difference to sort the columns first.


**Question:** What are the expected value and variance (or more generally, the probability distribution) of the $(i,j)$ entry of the matrix?


I imagine that exact answers should be very complicated, so approximate or asymptotic answers (as $n \gg 1$) may be even better.


A variation of the problem is to take each entry uniformly distributed on $\{0,1\}$ (i.e., a fair coin toss). The bi-sorting won't be necessarily unique, but in that case we choose randomly among the possibilities, say.


PS: Here is the output of an experiment with $n=20$:
$$
\begin{array}{cccccccccccccccccccc}
0 &0 &0 &1 &1 &0 &0 &0 &0 &1 &0 &1 &0 &0 &1 &1 &0 &1 &1 &0 \\
1 &0 &0 &0 &0 &0 &1 &0 &1 &1 &1 &0 &0 &1 &0 &1 &1 &0 &0 &1 \\
0 &1 &1 &0 &0 &0 &1 &0 &0 &1 &0 &1 &0 &0 &1 &0 &0 &1 &1 &1 \\
0 &0 &0 &0 &0 &0 &1 &0 &0 &1 &1 &1 &1 &1 &1 &0 &0 &1 &1 &0 \\
0 &1 &0 &0 &0 &1 &1 &1 &0 &0 &0 &1 &1 &0 &0 &0 &1 &1 &0 &1 \\
1 &1 &0 &0 &0 &0 &1 &1 &0 &1 &1 &1 &1 &1 &0 &1 &0 &0 &0 &0 \\
0 &0 &1 &0 &1 &0 &0 &1 &1 &1 &1 &0 &1 &1 &0 &0 &1 &0 &1 &0 \\
0 &1 &0 &1 &0 &1 &0 &1 &1 &0 &0 &0 &1 &1 &0 &0 &1 &0 &1 &1 \\
1 &0 &0 &1 &0 &0 &0 &1 &1 &0 &0 &0 &1 &0 &1 &1 &1 &0 &1 &1 \\
0 &1 &0 &0 &0 &1 &1 &0 &1 &0 &1 &0 &0 &1 &1 &1 &0 &0 &1 &1 \\
0 &0 &1 &1 &0 &1 &0 &0 &1 &1 &1 &1 &0 &1 &1 &0 &1 &0 &1 &0 \\
0 &1 &1 &0 &1 &1 &0 &0 &0 &1 &1 &0 &0 &1 &0 &1 &0 &1 &1 &1 \\
0 &0 &1 &1 &1 &1 &0 &1 &1 &0 &1 &0 &0 &0 &0 &1 &1 &1 &1 &1 \\
0 &0 &0 &0 &1 &1 &1 &1 &0 &1 &0 &1 &1 &0 &1 &0 &1 &1 &1 &1 \\
1 &0 &1 &1 &0 &1 &0 &0 &0 &0 &0 &1 &1 &1 &1 &1 &0 &1 &1 &1 \\
1 &0 &0 &1 &1 &0 &1 &1 &1 &1 &1 &0 &0 &1 &1 &0 &1 &1 &0 &1 \\
0 &1 &0 &1 &1 &0 &1 &1 &1 &0 &0 &1 &1 &1 &0 &1 &1 &1 &0 &1 \\
0 &1 &1 &1 &1 &0 &0 &1 &0 &0 &1 &1 &1 &0 &1 &1 &1 &1 &1 &1 \\
0 &0 &1 &0 &1 &1 &1 &0 &1 &1 &1 &1 &1 &1 &1 &1 &1 &1 &0 &0 \\
1 &1 &1 &1 &1 &1 &1 &1 &1 &1 &1 &1 &1 &0 &1 &1 &1 &1 &1 &1
\end{array}
$$
As expected, $0$s are more concentrated around the upper left corner, while $1$s are more concentrated around the lower right corner.



Distribution of entries of a doubly-sorted random matrix
Let $X$ be the array after your operation. The law of $X\_{i,j}$ for $(i,j)$ chosen in a deterministic way from $[1,..,n]^2$ converges to the uniform law. The tilting due to your operations is very small, asymptotically - since the maximal row sum is of order $\sqrt{n}$ with a logarithmic correction, the distribution you get for $X\_{i,j}$ is essentially an exponential tilting of uniform with mean of order 
$1/2+O(\log n/\sqrt{n})$. Not very much, and not enough to affect the limit law.


