I'm currently facing a problem where I need to perturb a provided vector $\vec{v}$ to produce a new vector $\vec{w}$, where both are located in $\mathbb{R}^n$, by perturbing both the magnitude and orientation of $\vec{v}$. The first part of this perturbation is straightforward, as I will only need to perturb the magnitude of $\vec{v}$ such that $$ m = \frac{\lVert\vec{w}\rVert}{\lVert\vec{v}\rVert} \sim Q, $$ where $Q$ is some specified probability distribution that can be sampled from. Put short, the result of this perturbation will just be a scalar multiplication of the original vector $\vec{v}$ (i.e. $\lVert \vec{w} \rVert = \lVert m \vec{v}\rVert$).
The second part of this perturbation is much harder. At the end of the perturbation, the new vector $\vec{w}$ must be oriented such that it is located at a specific angle $\theta$ away from $\vec{v}$, $$ \theta = \arccos\left(\frac{\vec{v}\cdot\vec{w}}{\lVert\vec{v}\rVert\lVert\vec{w}\rVert}\right) \sim U, $$ where $U$ is another specified probability distribution. With the exception of this constraint, the new vector $\vec{w}$ should be randomly oriented.
Whether or not this is useful, another way of thinking of this problem is that the new vector $\vec{w}$ must lie on the surface of the $n$-cone that is an angle $\theta$ away from $\vec{v}$, with the constraint such that it have a magnitude $m\lVert v \rVert$. These two constraints should limit the possible vectors to a $(n-2)$-dimensional surface (i.e. in $\mathbb{R}^3$, this amounts to choosing a random position on a circle).
What is the best way to go about this? I have found previous solutions for producing a random orientation in $\mathbb{R}^n$, but I can't come up with a way to also implement these constraints.
As i wrote in the comments, the problem can be solved by using spherical coordinates.
Without restriction of generality let $\vec{v} = (1, \dots ,0)$.
We can describe any point $x = (x_1, \dots , x_n) \in \mathbb{R}^n \setminus \{0\}$ by its unique spherical coordinates $(r,\varphi_1 ,s) \in (0,\infty) \times [0,\pi] \times \mathbb{S}^{n-2}$, where $\mathbb{S}^{n-2}$ is the $n-2$ dimensional sphere (assuming $n>2$). With the relation between them given by
\begin{align} x_1 &= r \cos(\varphi_1) \\ x_2 &= r \sin(\varphi_1) s_1 \\ x_3 &= r \sin (\varphi_1)s_2 \\ &\vdots \\ x_n &= r \sin (\varphi_1) s_{n-2}, \end{align} where $s= (s_1, \dots , s_{n-2})$.
The angle between $\vec{v}$ and $x$ is $\varphi_1$ and $\|x\| =r$.
Your problem is therefore solved by the following procedure:
Edit
I just realized that there was a big mistake in my answer. The uniform distribution in the angular variables and then using the coordinate transform will not yield the uniform distribution on the $n-2$ sphere.
Instead we can sample from the uniform distribution on the $n-2$ sphere using this. I have changed the above procedure so that it actually works.