How to measure whether a discrete distribution is uniform or not? Say I have two vectors [1,2,1,2,2] and [1,2,1,1,1]. The number at each dimension is the frequency of one element. How do I measure whether these two vectors are close to the uniform distribution? I know if this is continuous values, I can calculate the entropy of the two vectors. The one with higher entropy is closer to  a uniform distribution. But now I am solving a discrete optimization problem so I can only use integer values.
Currently, I am thinking calculating the value max([1,2,1,2,2]) - min([1,2,1,2,2]). The vector with the lower score is  closer to the uniform distribution. Is there a better method?
 A: Your suggestion should work.
I'm going to make another suggestion, which also yields an integer value for the discrepancy from uniformity. As indicated in comments, we don't really have enough information to say whether it's better for your application.
The usual chi-squared goodness of fit statistic is $\sum_i (O_i-E_i)^2/E_i$ (where $O_i$ is the observed count in category $i$ and $E_i$ is the expected count). When used for deviation from perfect uniformity, $E_i=N/k$, where $N=\sum_i O_i$ is the total count and $k$ is the number of categories.
This chi-squared statistic from uniformity is also related to the simple variance of the counts.
Note that this statistic simplifies in the uniformity case, as follows:
\begin{eqnarray}
\sum_i (O_i-E_i)^2/E_i &=& \sum_i (O_i-N/k)^2/(N/k)\\
&=& \frac{k}{N} \sum_i (O_i-N/k)^2\\ 
&=& \frac{k}{N} \sum_i [O_i^2-2N/k\cdot O_i+(N/k)^2]\\ 
&=& \frac{k}{N} [\sum_i O_i^2-2N/k \sum_i O_i+\sum_i (N/k)^2)]\\
&=& \frac{k}{N} [\sum_i O_i^2-2N/k\cdot N+ k\cdot(N/k)^2)]\\
&=& (\frac{k}{N} \sum_i O_i^2)-2N+ N\\
&=& (\frac{k}{N} \sum_i O_i^2)-N 
\end{eqnarray}
A simple linear rescaling of the chi-squared statistic is then $\sum_i O_i^2$, which will be integer-valued.
With $r={N\mod k}$, you could compute the smallest possible such value by putting $\lfloor N/k\rfloor$ (the average count rounded down) into $k-r$ bins and $\lceil N/k \rceil$ (the same, rounded up) into $r$  bins. It would be reasonable - but not necessary - to subtract the sum of squared counts for this arrangement from the above sum of squared counts. This would give an arrangement like $[1,2,1,2,2]$ get the value $0$, since it cannot be made smaller. If you'd like such an arrangement to get a non-zero value, the value of $\sum O_i^2$ under exactly equal allocation is $N^2/k$, but this won't be an integer in such cases, so you'd need to round that down before subtracting from $\sum O_i^2$ (rounding down would mean the difference $(\sum O_i^2)-\lfloor N^2/k\rfloor$ would only be exactly zero when the spread was perfectly uniform).
A: You can just as well use entropy in the discrete case as in the continuous case. The discrete uniform distribution on, say, $\{ 1,2,\dotsc,n  \}$ also maximizes entropy among all distributions on that same support. Note that it does not matter if that support set is integers on just indices into some discrete set $\{ x_1, x_2, \dotsc, x_n  \}$ since the entropy
$$
    H=-\sum_i p_i \log p_i
$$
does not involve at all the actual values in the support set. That is an important difference from the continuous entropy $-\int f(x)\log f(x)\; dx$ which actually uses the values in the support via the differential $d x$.
So just use entropy, but there are also other possibilities.
