TITLE: Taking points uniformly inside a general finite geometric domain
QUESTION [8 upvotes]: It is well known that if we want to  take $n$  uniformly and randomly points inside a circle of radius $r$ and centered at the origin the following apparently correct approach for generating  $x$ and $y$
$$ x= U \cos(\theta), \;y= U \sin(\theta)$$ where $U$ is a uniform variate in $(0,1)$  and $\theta$  is uniform variate in $(0, 2 \pi)$, does not work. Rather the correct way to generate  $x$ and $y$ coordinates is to use:
$$ x= \sqrt{U}\cos(\theta),\; y= \sqrt{U} \sin(\theta) $$ with $U$ and $\theta $ as mentioned above. I wonder is there a some way of generating  a  of $n$ points inside the bounded region defined  by
$$\mathbf{D}=\{(x,y):f(x,y)=0\},$$
given that $  \mathbf{D}$  forms a closed region with smooth boundary.
For instance let's say
$$\mathbf{D}=\{ (x,y):\frac{x^2}{a^2}+\frac{y^2}{b^2}=1\},$$
how can we create $n$ points that are uniformly distributed  inside the ellipse. Thanks for any hints/responses in advance!

REPLY [6 votes]: The approach (already alluded to in one of the answers) of sampling uniformly from a larger set and then throwing out the samples that you don't want is known as  rejection sampling. You'll find all sorts of useful ideas in the linked Wikipedia article and references thereof.