# Uniform sampling

Back to PastelMath

Uniform sampling of $V \subset {\mathbb{R}}^{n}$ is the problem of generating random samples from $V$ with a uniform distribution.

## Practice

In the following we assume that we are able to uniformly sample a real interval. A general algorithm to uniformly sample any set $V$ is to bound it with an axis-aligned box $B$, draw samples from a uniform distribution on $B$, and accept only those samples which are also in $V$. This is called rejection sampling. The probability that a sample drawn from $B$ is also in $V$ is the ratio of the measures of $V$ and $B$. Thus the efficiency is highly dependent on this ratio. Unfortunately, this ratio is often low, or even zero. For example, uniformly sampling the surface of a sphere in ${\mathbb{R}}^{3}$ would not succeed using rejection sampling in the described manner.

Thus, more than often it is either necessary, or much more efficient, to generate uniform samplings via slightly more complex algorithms. Pastel implements efficient algorithms to uniform sample from:

• a box in ${\mathbb{R}}^{n}$
• a sphere (surface) in ${\mathbb{R}}^{n}$
• a ball in ${\mathbb{R}}^{n}$
• an annulus in ${\mathbb{R}}^{n}$

If instead you need to distort an existing uniform sampling from one shape to another, see the link below.