Distance of two points in the Unit Interval

First I will show how to define a function that will calculate the distance between two real numbers given as a pair {x,y}

Abs[#[[1]]-#[[2]]]&[{x,y}]

RandomReal[{0,1},2]

Thus, the distance of two random real numbers in the interval [0,1] is

Abs[#[[1]]-#[[2]]]&[RandomReal[{0,1},2]]

Now we can calculate a mean of 1000 random distances:

Mean[Table[Abs[#[[1]]-#[[2]]]&[RandomReal[{0,1},2]],{k,1,1000}]]

Or, we can calculate a mean of 100,000 random distances:

Mean[Table[Abs[#[[1]]-#[[2]]]&[RandomReal[{0,1},2]],{k,1,100000}]]

Or, we can calculate a mean of 1,000,000 random distances:

Mean[Table[Abs[#[[1]]-#[[2]]]&[RandomReal[{0,1},2]],{k,1,1000000}]]

Or, we can calculate a mean of 10,000,000 random distances:

Mean[Table[Abs[#[[1]]-#[[2]]]&[RandomReal[{0,1},2]],{k,1,10000000}]]

Distance of two points on a circle

Mean[Table[ (Sqrt[(((Cos[2 Pi#[[1]]]-Cos[2 Pi#[[2]]]))^2)+(((Sin[2 Pi#[[1]]]-Sin[2 Pi#[[2]]]))^2)]) &[RandomReal[{0,1},2]],{k,1,10000000}]]

N[4/Pi]

Distance of two points in the unit square

RandomReal[{0,1},4]

Mean[Table[ (Sqrt[(((#[[1]]-#[[3]]))^2)+(((#[[2]]-#[[4]]))^2)]) &[RandomReal[{0,1},4]],{k,1,10000000}]]

N[(1/15)(2+(Sqrt[2])+5Log[1+(Sqrt[2])])]

We need to calculate the quadruple intgral

(∫_0^1)(∫_0^1)(∫_0^1)(∫_0^1)(Sqrt[((((Subscript[x, 1])-(Subscript[x, 2])))^2)+((((Subscript[y, 1])-(Subscript[y, 2])))^2)])d(Subscript[x, 1])d(Subscript[x, 2])d(Subscript[y, 1])d(Subscript[y, 2])

Below I calculate this integral step by step, using the option Assumptions.

Integrate[(Sqrt[(((x-y))^2)+a]),{x,0,1},Assumptions-> And[y>0,y<1,a>0]]

FullSimplify[(1/2) ((Sqrt[a+(((-1+y))^2)])-(Sqrt[a+(((-1+y))^2)]) y+y (Sqrt[a+(y^2)])+a Log[1+(Sqrt[a+(((-1+y))^2)])-y]-a Log[-y+(Sqrt[a+(y^2)])]),And[y>0,y<1,a>0]]

Integrate[(1/2) ((Sqrt[a+(((-1+y))^2)])-(Sqrt[a+(((-1+y))^2)]) y+y (Sqrt[a+(y^2)])+a Log[1+(Sqrt[a+(((-1+y))^2)])-y]-a Log[-y+(Sqrt[a+(y^2)])]),{y,0,1},Assumptions-> And[a>0,a<1]]

((1/6) (4 (a^(3/2))+2 (Sqrt[1+a])-4 a (Sqrt[1+a])+3 a Log[a]-6 a Log[-1+(Sqrt[1+a])]))/.{a->(((z-w))^2)}

Integrate[(1/6) (4 ((((((-w+z))^2)))^(3/2))+2 (Sqrt[1+(((-w+z))^2)])-4 (((-w+z))^2) (Sqrt[1+(((-w+z))^2)])+3 (((-w+z))^2) Log[(((-w+z))^2)]-6 (((-w+z))^2) Log[-1+(Sqrt[1+(((-w+z))^2)])]),{z,0,1},Assumptions->And[w>0,w<1]]

Integrate[(1/12) (2-8 w+12 (w^2)-8 (w^3)+4 (w^4)+3 w (Sqrt[1+(w^2)])-2 (w^3) (Sqrt[1+(w^2)])+(Sqrt[2-2 w+(w^2)])+3 w (Sqrt[2-2 w+(w^2)])-6 (w^2) (Sqrt[2-2 w+(w^2)])+2 (w^3) (Sqrt[2-2 w+(w^2)])+ArcSinh[1-w]+ArcSinh[w]+2 Log[(((-1+w))^2)]-6 w Log[(((-1+w))^2)]+6 (w^2) Log[(((-1+w))^2)]-2 (w^3) Log[(((-1+w))^2)]+4 (w^3) Log[w]-4 Log[-1+(Sqrt[2+(-2+w) w])]+12 w Log[-1+(Sqrt[2+(-2+w) w])]-12 (w^2) Log[-1+(Sqrt[2+(-2+w) w])]+4 (w^3) Log[((-1+(Sqrt[2+(-2+w) w]))/(-1+(Sqrt[1+(w^2)])))]),{w,0,1}]

N[(1/15) (2+(Sqrt[2])+5 ArcSinh[1])]

Distance of two points in the unit disk

RandomReal[{-1,1},4]

Partition[RandomReal[{-1,1},4],2]

tblppnts=Table[Partition[RandomReal[{-1,1},4],2],{k,1,10000000}];

The next command takes a long time to evaluate.

ppntsDisk=Select[tblppnts,And[Norm[#[[1]]]≤1,Norm[#[[2]]]≤1]&];

Length[ppntsDisk]

ppntsDisk[[1]]

ppntsDisk[[1]][[1]]

ppntsDisk[[1]][[1,1]]

ppntsDisk[[1]][[1,2]]

Mean[(Sqrt[(((#[[1,1]]-#[[2,1]]))^2)+(((#[[1,2]]-#[[2,2]]))^2)]) &/@ppntsDisk]

N[(128/(45π))]