Suppose we pick pairs of triples from $\{ 0, 1, 2, \dots, 255\}^3$ with a uniform distribution and would like to find a closed form for the distribution of the Euclidean distances
$$ d((x_1, x_2, x_3), (y_1, y_2, y_3)) = \left( \sum_{j=1}^3 (x_j-y_j)^2 \right)^{1/2}.$$
The motivation for this question comes from the cubic lattice that is one of the RGB color spaces. It would be nice to have an exact probability distribution because it would likely have interesting applications in image processing.
This question gives the answer for when a cube includes all real numbers in it, and there's Mathai et al.$^\color{magenta}{\star}$, but what about when it is discrete, like for a cubic lattice?
$\color{magenta}{\star}$ Arak M. Mathai, Peter Moschopoulos, Giorgio Pederzoli, Distance between random points in a cube [PDF], Statistica, Volume 59, Number 1, 1999.
Brute force computation works, with the following trick.
The square root expression for the distance $d$ between $(x_1, x_2, x_3), (y_1, y_2, y_3)$ is equivalent to
$$ d^2 = (x_1 - y_1)^2 + (x_2 - y_2)^2 + (x_3 - y_3)^2 $$
Each term on the RHS is a perfect square and is bounded by $256^2$. There are $256$ perfect squares less than $256^2$ (including $0$). We can trivially enumerate them. For each pair $(x,y), 0 \le x,y \le 255$ we can compute $(x-y)^2$ and build a frequency table $T$ containing entries $\langle (x-y)^2, \nu_{(x-y)^2}\rangle$ where $\nu_{(x-y)^2}$ is the frequency of $(x-y)^2$. We treat this table as a set and identify the entries in it by the pair $(s,\nu)$.
For each triple $((s_1, \nu_1), (s_2, \nu_2), (s_3, \nu_3)) \in T \times T \times T$, we compute the pair
$$ (s,\nu) = (s_1 + s_2 + s_3, \nu_1 \nu_2 \nu_3) $$
Call this result set $U$.
$U$ gives the distribution of the squares $s = d^2 \lt 256^2$. We should aggregate the frequency by $s$.
i.e.,
$$V = \{(s, \nu) : \nu = \sum_{(s^{\prime}, \nu^{\prime}) \in U} \nu^{\prime} \text{ where $s^{\prime} = s$ }\}$$
Since we are interested in the distribution of $d$, the positive square root of $d^2$ only, we use the same aggregate frequency. i.e., the map
$$ (s, \nu) \rightarrow (\sqrt{s}, \nu) $$
The following C# program implements the above: