# Generating samples within a sphere according to a specified distribution

Let's consider a ball in $\mathbb{R}^n$ centered at some point $x$ with radius $r$. I am interested in generating samples (random points) within this ball. It is well known that, according to sources such as link, using Gaussian random variables and normalizing them produces random points that are uniformly distributed within a sphere.

Now let's say I want to generate random points within this ball according to a specified distribution. Are there general procedures for doing this? Or, are there other known specific approaches that produce specific distributions within the ball?

• Please add some of your ideas by editing the question. – callculus Mar 4 '18 at 15:41
• It's not a homework question. I'm trying to do a simulation that I'm interested in and happened to need to do this. I was wondering if others have heard of it because I'm looking for references – Tomas Jorovic Mar 4 '18 at 15:57

If you can generate random samples uniformly distributed within the $n$-dimensional sphere then you can generate other distributions by the rejection sampling method.
Here, I am going to describe the above mentioned method if the $n$-dimensional density, $f$ exists and is bounded by, say, $B$ inside the sphere. (It is zero outside the same.)
Now, let your uniformly distributed samples denoted by $\{\vec X_n\}$. Take independent random numbers, $\{Y_n\}$ uniformly distributed over $[0,B]$. Then take the sample of the pairs: $\{(\vec X_n, Y_n)\}$.
Accept $\vec X_n$ if $$f(\vec X_n)\leq B_n$$ reject it otherwise. The distribution of the accepted samples will be of $f$.
• Practical for small dimensions $n$. (+1) But for large $n$ the proportion of 'accepted' points will be very small compared to 'rejected' ones. [For example, the standard multivariate normal probability of the unit ball in 10-D is computed in R as pchisq(1,10) which returns 0.0001721156.] In higher dimensions, maybe better to use an MCMC method such as a constrained random walk. – BruceET Mar 4 '18 at 18:58