0

So I want to create a random point in a m-dimensional space (with m>2) that is k units away from the origin.

My first guess was to randomly draw m-1 angels (from a uniform distribution from 0 to 2pi) and then use the cosine of each of these angels times the length k, such that I get the projection onto each of the axes and thus the coordinate in that specific direction (cartesian coordinates). The last coordinate I would determine by using the euclidean distance namely k^2 minus the sum of the (m-1) squared cartesian coordinates.

However, doing this can cause the k^2 to be smaller than the sum of all the m-1 coordinates squared and thus ending up with a complex number when taking the square root.

So what is the correct way to drawing random points that are exactly k units away from the origin?

1 Answers1

2

You are effectively choosing a random point on the surface of an $m$-dimensional sphere with radius $k$.

Method 1. One way to do this is to independently generate $m$ random points $x_1, \ldots, x_m$ on a normal distribution $N(0,1)$. Then just scale the vector $[x_1, \ldots, x_m]$ so that it has length $k$.

Method 2. Another way, which is straightforward but a bit wasteful, is to generate a random point $P$ inside the cube of side length $2k$ (i.e., the cube circumscribing the desired sphere). Each co-ordinate would be chosen uniformly at random from the interval $[-k,k]$. If $P$ happens to be outside the sphere, throw it away and try again. If $P$ is inside the sphere, then project it onto the sphere, i.e., scale it so that its length is $k$.

Théophile
  • 24,627