How to find the expected distance between two uniformly distributed points? If I were to define the coordinates $(X_{1},Y_{1})$ and $(X_{2},Y_{2})$ where 
$$X_{1},X_{2} \sim \text{Unif}(0,30)\text{ and }Y_{1},Y_{2} \sim \text{Unif}(0,40).$$
How would I find the expected value of the distance between them?
I was thinking, since the distance is calculated by $\sqrt{(X_{1}-X_{2})^{2} + (Y_{1}-Y_{2})^{2}})$ would the expected value just be $(1/30 + 1/30)^2 + (1/40+1/40)^2$?
 A: ##problem
x <- runif(1000000,0,30)
y <- runif(1000000,0,40)
Uniform <- as.data.frame(cbind(x,y))
n <- nrow(Uniform)
catch <- rep(NA,n)
for (i in 2:n) {
      catch[i] <-((x[i+1]-x[i])^2 + (y[i+1]-y[i])^2)^.5
}
mean(catch, na.rm=TRUE)
18.35855

If I understand correctly what you're looking for, maybe this helps.  You're trying to figure out the distance between to random points, who's X values are generated from unif(0,30) and Y values are generated from a unif (0,40).  I just created a million RV's from each of those to distributions and then bound the x and the y to create a point for each of them.  Then I calculated the distance between point 2 and 1 all the way to the distance between points 1,000,000 and 999,999.  The average distance was 18.35855.  Let me know if this isn't what you were looking for.  
A: It is plain, from looking at the question geometrically, that the expected distance between two independent, uniform, random points within a convex set is going to be a little less than half its diameter.  (It should be less because it's relatively rare for the two points to be located within extreme areas like corners and more often the case they will be near the center, where they are close.)  Since the diameter of this rectangle is $50$, by this reasoning alone we would anticipate the answer to be a little less than $25$.
An exact answer is obtained from the definition of expectation as the probability-weighted value of the distance.  In general, consider a rectangle of sides $1$ and $\lambda$; we will scale it up to the correct size afterwards (by setting $\lambda = 40/30$ and multiplying the expectation by $30$).  For this rectangle, using coordinates $(x,y)$, the uniform probability density is $\frac{1}{\lambda}dx dy$. The mean distance within this rectangle then is given by
$$\int_0^\lambda\int_0^1\int_0^\lambda\int_0^1 \sqrt{(x_1-x_2)^2+(y_1-y_2)^2} \frac{1}{\lambda}dx_1  dy_1 \frac{1}{\lambda} dx_2 dy_2.$$
Using elementary integration methods this is straightforward but painful to do; I employed a computer algebra system (Mathematica) to obtain the answer
$$[2+2 \lambda ^5-2 \sqrt{1+\lambda ^2}+6 \lambda ^2 \sqrt{1+\lambda ^2}-2 \lambda ^4 \sqrt{1+\lambda ^2} +5 \lambda  \text{ArcSinh}(\lambda)+5 \lambda ^4 \log\left(\frac{1+\sqrt{1+\lambda ^2}}{\lambda }\right)]/(30\lambda^2).$$
The presence of $\sqrt{1+\lambda^2}$ in many of these terms is no surprise: it is the diameter of the rectangle (the maximum possible distance between any two points within it).  The appearance of logarithms (which includes the arcsinh) is also unsurprising if you have ever investigated average distances within simple plane figures: somehow it always shows up (a hint of this appears in integral of the secant function).  Incidentally, the presence of $30$ in the denominator has nothing to do with the specifics of the problem involving a rectangle of sides $30$ and $40$: it's a universal constant.)
With $\lambda=4/3$ and scaling up by a factor of $30$, this evaluates to $\frac{1}{108} (871+960 \log(2)+405 \log(3)) \approx 18.345919\ldots$.

One way to understand the situation more deeply is to plot the mean distance relative to the diameter of $\sqrt{1+\lambda^2}$ for varying values of $\lambda$. For extreme values (near $0$ or much greater than $1$), the rectangle becomes essentially one-dimensional and a more elementary integration indicates the mean distance should reduce to one-third the diameter.  Also, because the shapes of rectangles with $\lambda$ and $1/\lambda$ are the same, it is natural to plot the result on a logarithmic scale of $\lambda$, where it must be symmetric about $\lambda=1$ (the square).  Here it is:

With this we learn a rule of thumb: the mean distance within a rectangle is between $1/3 \approx 0.33$ and (approximately) $0.37$ of its diameter, with the larger values associated with squarish rectangles and the smaller values associated with long skinny (linear) rectangles.  The midpoint between these extremes is achieved roughly for rectangles with aspect ratios of $3:1$.  With this rule in mind, you can just glance at a rectangle and estimate its mean distance to two significant figures.
