Algorithm to generate an uniform distribution of points in the volume of an hypersphere/on the surface of an hypersphere.

Solution 1:

Aperantly, for picking points on the surface of a hypersphere is to generate $n$ Gaussian random variables $x_1, x_2, ...x_n$, and then use the vectors:

$$\frac{1}{\sqrt{x_1^2+x_2^2+...+x_n^2}} \left( \begin{array}{c} x_1\\ x_2\\ ..\\ x_n\\ \end{array} \right)$$ Which will be uniformly distributed on the the surface of the hypersphere.

Solution 2:

For the volume I'd say the simlest algorithm would be a standard accept-reject algorithm.

(1) draw a uniform random point within an n-dimensional hypercube
(2) repeat (1) if the distance exceeds $r$, otherwise done

if im not mistaken though, accept-rates decrease as $n$ increases, maybe there is something more efficient

edit you can also find some ideas here: Picking random points in the volume of sphere with uniform probability

edit2 thanks to @awkward for pointing out that my suggestion to draw uniformly distributed angles is not a valid method to obtain points on the surface