Why can the a combination of an exponential and logarithmus function be used to create a powerlaw distribution I answered a question on StackOverflow where a person wanted a randomized function that produces as many numbers between 0-10, 10-100 and 100-1000.
I offered the following function that does the job:
Math.floor(Math.exp(Math.random()*Math.log(maxmimum-minimum+1)))+minimum

In the comments, I was asked why this function works for the job and I can't come up with a good explanation. It's just obvious to me that it works.
Can someone provide a good explanation of why it works?

One way to generate random numbers according to a particular distribution is to generate random numbers on $[0,1)$ and then use the inverse cumulative distribution function give the distribution.
You want your cumulative distribution function (before rounding to integers) to be of the form $a\log(x)+b$ between two values $m$ and $M$. Since $F(m)=0$ and $F(M)=1$, this gives $b=-a\log(m)$ and $a=\frac{1}{\log(M)-\log(m)}$, so $$F(x)=\frac{\log(x)-\log(m)}{\log(M)-\log(m)}$$ when $m\lt x \lt M$.  Its inverse is $$F^{-1}(y) = e^{y(\log(M)-\log(m))+\log(m)}=e^{y(\log(M)-\log(m))}m = m\left(\frac{M}{m}\right)^y$$
Now you can just plug your uniform random number $Y$ on $[0,1)$ into any of these expressions; you chose something close to $e^{y(\log(M)-\log(m))}m$.  
Since you are then going to round down to an integer, you want $M$ equal to maximum+1 and $m$ equal to minimum and that more or less gives your expression  
