Why does $\frac1\pi\int_0^\pi|\cos t|dt$ estimate the average size of $|u\cdot U_j$|, where $u$ and thirty $U_j$s are random unit vectors? Why is the highlighted part true? and what is the hidden meaning behind average size of $\rvert u.U_j \rvert$?

Here is what I did to solve:

The solution that I got:

 A: Due to symmetry of the system, you can fix the direction of $\mathbf u$ e.g. to go along $x$. Then the average should be:
$$
\frac1{|\Omega|}\int_\Omega|U_x|d\Omega
$$
If we are talking about 2 dimensional vectors, then $\Omega$ is the unit circle, and with polar parameterization ($U_x=\cos\theta$):
$$
\frac{1}{2\pi}\int_0^{2\pi}|\cos\theta|d\theta=\frac{1}{\pi}\int_0^{\pi}|\cos\theta|d\theta = \frac{2}{\pi}=0.63662.
$$
However, we work in 3D, thus $\Omega$ is a unit sphere and with spherical parameterization ($U_x=\cos\theta$, $d\Omega=\sin\theta\, d\theta\, d\varphi$):
$$
\frac{1}{4\pi}\int_0^{2\pi}d\varphi\int_0^{\pi}|\cos\theta|\sin\theta\, d\theta=\frac{1}{2}\int_{-1}^1|z|dz = \frac12.
$$
So you should expect the answer to be closer to $0.5$. If you up the number of vectors from $30$ to $10^6$, you will see that.
In other words, the book should either ask you to have randn(2, 1)/randn(2, 30), or should give you an integral for 3D case. You might check that with 2D case the average is indeed $2/\pi$.
A: Let $U \sim U(\Bbb{S}^1)$ be a random vector with uniform distribution on the unit sphere. For a fixed unit vector $\mathbf{u} = (\cos\phi, \sin\phi)$ we have
\begin{align}
\Bbb{E}|\langle u,U\rangle| &= \int_{\Bbb{S}^1} |\langle \mathbf{u},\mathbf{x}\rangle| \,d\mathbb{P}_U(x)\\
&= \frac1{2\pi}\int_{\Bbb{S}^1} |\langle \mathbf{u},\mathbf{x}\rangle|\,d\lambda(\mathbf{x})\\
&= \frac1{2\pi} \int_0^{2\pi} |\langle (u_1,u_2),(\cos\theta, \sin\theta)\rangle|\,d\theta\\
&= \frac1{2\pi} \int_0^{2\pi} |u_1\cos\theta + u_2\sin\theta|\,d\theta\\
&= \frac1{2\pi} \int_0^{2\pi} |\cos\phi\cos\theta + \sin\phi\sin\theta|\,d\theta\\
&= \frac1{2\pi} \int_0^{2\pi} |\cos(\phi-\theta)|\,d\theta\\
&= \frac1{2\pi} \int_\phi^{\phi +2\pi} |\cos(\theta)|\,d\theta\\
&= \frac1{\pi}\int_0^{\pi} |\cos\theta|\,d\theta
\end{align}
since $\cos$ is $\pi$-periodic. More formally
$$ \int_\phi^{\phi +2\pi} |\cos(\theta)|\,d\theta = \int_\phi^{2\pi} |\cos\theta|\,d\theta + \int_{2\pi}^{\phi+2\pi} |\cos\theta|\,d\theta  = \int_\phi^{2\pi} |\cos\theta|\,d\theta + \int_{0}^{\phi} |\cos(\theta+2\pi)|\,d\theta \\
= \int_\phi^{2\pi} |\cos\theta|\,d\theta + \int_{0}^{\phi} |\cos(\theta)|\,d\theta = \int_0^{2\pi}|\cos\theta|\,d\theta = \int_0^\pi |\cos\theta|\,d\theta + \int_\pi^{2\pi} |\cos\theta|\,d\theta \\= \int_0^\pi |\cos\theta|\,d\theta + \int_0^{\pi} |\cos(\theta+\pi)|\,d\theta =  \int_0^\pi |\cos\theta|\,d\theta + \int_0^{\pi} |\cos(\theta)|\,d\theta = 2\int_0^{\pi} |\cos(\theta)|\,d\theta.
$$
