I need to pick random points inside a sphere (or ball) of radius $R$ such that the expected density of points is a linear function of the distance from the center.

To be more precise, for two given values $a$ and $b$ (measured in points per unit volume), I need the density of points inside the sphere to be approximately $f(r)=a+\frac{b-a}{R}\cdot r$, where $r$ is the distance from the center of the sphere.

All the Methods I could find online where aimed at picking points with a uniform distribution, which is not what I need.

Since picking a point with uniform distribution on the surface of the unit sphere is easy, I would like to use that method as a first step and then scale the resulting vectors by some random variable $r$.

What probability distribution should $r$ have?

  • $\begingroup$ If you want the probability density to be exactly $f(r)$ then $\int f(r) 4\pi r^2 \, dr= 1$ imposes a condition on $a$ and $b$. Maybe you just want to density to be proportional to $f(r)$? $\endgroup$
    – ronno
    Apr 5, 2023 at 11:51
  • $\begingroup$ @ronno $f(r)$ is not a probability density, it is the density of points (number of points per unit of volume). $\endgroup$ Apr 5, 2023 at 17:09

1 Answer 1


$r$ should have probability distribution proportional to $4\pi r^2f(r)$, since the shells at radius $r$ are "spread out" over a larger surface area.

  • $\begingroup$ So you want to integrate this from $0$ to $R$ so you can scale it to be $1$. The CDF for $r$ will be a 4th degree polynomial, so messy to invert, though there are other methods of sampling values such as rejection sampling. $\endgroup$
    – Henry
    Apr 5, 2023 at 12:25

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .