2
$\begingroup$

I've seen many different approaches to generate a random vector in the ($n-1$)-sphere and in the $n$-ball. One of them is generating a normal n-vector v (all components $x_i\sim N(0,1)$) and then normalizing the vector. For some weird reason I cannot quite understand this vector is uniformly distributed in the ($n-1$)-sphere. For the inside of the $n$-ball I choose a random uniform $u\sim U(0,1)$ and then multiply $v \cdot \sqrt[n]{u}$.

Now I need to generate a uniform n-vector inside an $n$-ring (the volume between two $n$-balls of radio $r_1$ and $r_2$). I did it by generating a $u\sim U(a,b)$ such that $\sqrt[n]{a} = r_1$ and $\sqrt[n]{b} = r_2$, and follow the same approach as before.

My question is: Is this correct, or is there another better (and/or faster) method for this?

I'll be generating many of these vectors in some high dimension ($> 1000$) for a meta-heuristic. Thanks in advance.

0 Answers 0