Let two random variables $X,Y$ be iid. on $\mathsf{U}_{\{1,\ldots,n\}}$. I am trying to find the expected value of $Z = |X-Y|$. This is my approach so far but I think there's something wrong:
Define $h(X,Y) = |X-Y|$. Then we have $$ \DeclareMathOperator{\EV}{\mathbb{E}} \begin{align*} \EV[Z] &= \EV[h(X,Y)] \\ &= \sum_{i=1}^n \sum_{j=1}^n h(x_i, y_j) P(X = x_i, Y = y_j) \\ &= \sum_{i=1}^n \sum_{j=1}^n |x_i - y_j| P(X = x_1)P(Y = y_1) \\ &= \sum_{i=1}^n \sum_{j=1}^n \frac{|x_i - y_j|}{n^2} \\ &= \frac{1}{n^2} \sum_{i=1}^n \sum_{j=1}^n |x_i - y_j| \end{align*} $$
So we need to evaluate $\sum_{i=1}^n \sum_{j=1}^n |x_i - y_j|$, where $x_i = i, y_j = j$. Thus, we would get something like this $$ \begin{align*} &|x_1 - y_1| + |x_1 - y_2| + \ldots + |x_1 - y_n| \\ +\,\, &|x_2 - y_1| + |x_2 - y_2| + \ldots + |x_2 - y_n| \\ +\,\, & \ldots \\ \end{align*} $$ which should give $$ 1 + 2 + \ldots + (n-1) \\ 1 + 2 + \ldots + (n-2) \\ \vdots \\ $$ Hence the double sum should be equal to $$ \sum_{k=1}^{n-1} k(n-k) = \frac{n^3-n}{6} $$ Which implies $$ \EV[Z] = \frac{n^2-1}{6n} $$
But I have the feeling this somehow can't be correct. Too hacky if I compare it to the result of the continuous case. But perhaps the discrete case just happens to involve this ugly sum.
Thanks for any help :)