Mathematical reason behind exponential distribution in random shuffling of balls in boxes Let's take a very simple problem where 1000 identical boxes initially each have 10 balls. Then we select at random one box, take out a ball from it and put it into another box chosen again randomly.
This algorithm repeated large number of times always give exponential distribution with most boxes being empty and only few with large number of balls.
Sample code for problem illustration:
import numpy as np  
import matplotlib.pyplot as plt  

box = np.ones(1000)  
box = box*10  
for i in range(100000):  
    rand = np.random.randint(low=0, high=1000, size=2)  
    if box[rand[0]] > 0:  
        box[rand[0]] = box[rand[0]] - 1  
        box[rand[1]] = box[rand[1]] + 1  
#     print(box)  
plt.hist(box,bins=50)  
plt.show()


Question:  
Probability of choosing a box is equal for any box, then can't we assume that in large number of trials, each box is chosen equal number of times for removal of ball and similarly each box is chosen equal number of times to add a ball to it?
Why after a large repeated trials, the number of balls in each box does not reach equilibrium value 10. Why most of the boxes are emptied and only handful are filled with huge number of balls. This seems counter-intuitive.
Is it something to do with the way random number generators are designed so we indeed get binomial distribution to imitate some physical behavior? Or there is a purely mathematical intuition behind?
 A: I will assume that the number of boxes is very large -- call it $n$ -- and the number of random steps in the experiment is much larger, such that we have reached whichever kind of steady state the experiment tends towards.
Intuitively, in the steady state a certain number of boxes will be non-empty at any given time. This number can fluctuate up and down a bit, but I will make the somewhat handwawy assumption that it stays near some limit mos of the time. Let's assume that the "usual" number of non-empty boxes is $kn$ for some constant $k\in(0,1)$.
Let's look at how the number of balls in any particular non-empty box evolves. At a given point in time there are $n-1$ different random pairs that will lead to the number decreasing by one, but only $kn-1$ different random pairs that will lead to the number increasing. So the probability that the next change to this particular box will be an increase is $\frac{kn-1}{n-1+kn-1}$. Since we're assuming $n$ to be large, we can ignore the $-1$s (they stand for the box being picked as both the "from" and "to" box at the same time), and say that the probability is $\frac{k}{1+k}$.
Thus, over a long time the number of balls in one single box will behave like a random walk that moves up with probability $\frac{k}{1+k}$ and down with probability $\frac{1}{1+k}$. There's a good theory of such random walks, and it says that the number of balls we expect to find in the is geometrically distributed exactly like you have observed. (That is, except that it only behaves according to the nice theory as long as the number is at least $1$. When it drops to $0$, the next step in the random wall is necessarily "up", but the waiting time until that step happens is different from the usual expectation, which the simple analysis so far doesn't take into account -- note, tough, that @zoli's answer contains the germ of a simple proof that the pattern does continue all the way to $0$).
In other words, as far as I can see, the system has no inherent dynamic that looks like "big boxes tend to stay big" -- all non-empty boxes shrink probabilistically at the same rate, and the few big ones you see are just flukes that have temporarily acquired a lot of balls.
The outcome of the random-walk calculation is very nice: it says that if the steady state has a certain amount of boxes with $m\ge 1$ balls, there will be $k$ times as many boxes with $m+1$ balls. (There is some handwaving going on here, pretending the counts of balls in different boxes are independent even though they're not really -- I'll gleefully sweep all that under the carpet, in the interest of getting a qualitative understanding for large $n$). We can use this to derive what $k$ must be. Namely, suppose that there are $\ell n$ boxes with one ball in them. Then the total number of live boxes is
$$ kn = \ell n  + k \ell n + k^2 \ell n + k^3 \ell n + \cdots = \frac{\ell n}{1-k} $$
which we can easily solve to get
$$ \ell = k(1-k) $$
We can also count the total number of balls:
$$ \ell n + 2 k \ell n + 3 k^2 \ell n + \cdots = \frac{\ell n}{(k-1)^2} = n\frac{k}{1-k} $$
Since we know there are really ten times as many balls as there are boxes, we can use this to find $k$:
$$ \frac{k}{1-k} = 10 ~\iff~ k = \frac{10}{11} = 0.909090\ldots$$

Let's check that this looks like a steady state. What is the probability that a random move will increase the number of empty boxes? It needs to move a ball from a size-1 box to a non-empty box other than itself), so the number of pairs that do this is
$$ \ell n \cdot kn - 1 = k^2(1-k) n^2 -1 $$
On the other hand, what is the chance to decrease decrease the number of empty boxes. For this we need to move a ball from a box of size $\ge 2$ to a previously empty box. The number of pairs that do this is
$$ (kn - \ell n) \cdot n - kn = (k - k(1-k))(1-k)n^2 = k^2(1-k) n^2 $$
That is, exactly the same, other than the $-1$ that we're ignoring because $n$ is large.
A: In the case of such an experiment (You choose an ordered pair of boxes and from the first box you take a ball and put it in the second box. If there is no ball in the first box then you repeat...), so in such a case, after a number of experiments the following distribution will be formed: all the numbers of balls in boxes are equally likely. For example $10\ 000$ balls in any of the boxes is equally likely as $10$ balls in each boxes. That means: many empty boxes is equally likely than many non-empty boxes.
This does not mean that many empty boxes are more likely than just a few.
A: I played with your code briefly.  It is interesting. Im no expert in probability or statistics.
Now, I removed your restrictions on a box having to have at least one ball in it in order for you to pull a ball out. As expected, some boxes ended up having a negative number of balls in it, but the distribution was more or less constant linear.  As you suggested, this seems reasonable. 
With that restriction reinstated, I also adjusted the number of iterations to be significantly fewer than what it was.  It was my intent to see what happens when you never allow a box to empty. This also holds true when you start your simulation with significantly more balls in each box; has the same effect. I did not get an exponential distribution, but I didnt get a linear constant distribution either.  
It is only when you allow the possibility for a box to be emptied do you start to see an exponential distribution.
I also modified your code to include a 20 ball maximum cap on each box, and again the exponential disappeared.
Lastly, with a 0 ball minimum and no maximum, I also pulled a quantity of balls from each box proportional to how many balls were in there.  I put those balls into boxes, both all-in-one and also distributed one-per-box randomly chosen. Again the exponential disappeared.
I cannot explain the exponential, specifically, as opposed to other distributions. But it seems to me that the mere fact you cannot pull a ball out of an empty box and there is no maximum are key to the result. It is also true that the probability of selecting a ball is not constant, as it changes with the number of empty boxes and is not proportional to the number of balls in a box. The equal chances of selecting each box, coupled with the fact that:


*

*You cannot pull a ball from an empty box (so you cannot diminish its quantity on this scenario)

*When you pull a ball from a box with a large number of balls in it already, it is less significantly effected as a matter of proportion than a box with a few number of balls in it, and stands a lesser chance of being emptied with each pull.  Thus, in a crude and naive way of thinking, you could argue that once a box has reached a certain amount it is guaranteed to never diminish below a certain level ever again in the finite amount of iterations youve allotted.


Or in another way of saying this, empty boxes are positively effected by putting and not effected at all by pulling, while boxes with a lot of balls are really neither positively nor negative effected in any noticeable or meaningful way over the finite period. 


*There is an asymmetry between pulling balls and putting balls.  The pulling of balls is restricted by the requirement that there are balls to be pulled. But there is no restriction on the putting of balls, as each box is given infinite capacity. 

*Lastly, as more and more boxes become empty, the probability of selecting an already empty box becomes higher and higher. As balls are consolidated into fewer and fewer boxes, the probability of pulling any ball at all on each iteration diminishes.


I believe there is some interplay between these four/five facts that give rise to the exponential. But I also believe that the asymmetry in bullet point 3 and the diminishing probability of puling any ball at all in bullet point 4 are probably the most significant influences.
