# Understanding the Rejection Sampling for a vector

I am thinking about this classical problem in statistical simulations. We want to apply the Rejection sampling to simulate a random vector $$Y=(Y_1, Y_2)$$ of a uniform distribution from a unit disc $$D = \{ (X_1 , X_2) \in R^2: \sqrt{x^2_1 + x^2_2} ≤ 1\}$$ such that $$X = (X_1 , X_ 2)$$ is random vector of a uniform distribution in the square $$S = [−1, 1]^2$$ and the joint density $$f(y_1,y_2) = \frac{1}{\pi} \mathbb{1}_{D(y_1,y_2)}.$$

Many answers presented a very simple solution like the answer of Haitao Du and page 26 but I can't understand how did they applied the rejection sampling method.

In the rejection method, we accept a sample generally if $$f(x) \leq C \times g(x)$$. In the linked answers they simply do

Repeat generate independent V1, V2  which distribute U(−1,1)
Until (V1)^2 + (V2)^2 <= 1
Return (V1,V2).


So the code

x=runif(1e4,-1,1)
y=runif(1e4,-1,1)

d=data.frame(x=x,y=y)
disc_sample=d[d$$x^2+d$$y^2<1,]
plot(disc_sample)


What I am can't understand how did they use the definition of Rejection sampling. Where did the define the constant $$C$$, the function $$g(x)$$ or even found the maximum of $$f(x)$$. I understand what did they do but I don't see how it is applying the definition of the Rejection sampling. Thanks for help

The maximum of $$f(x)$$ is the same as the value throughout, because of the uniformity. Therefore, we don't need to do the comparison.
By the way, there is a mistake in the code. d$x^2+d$y^2<1should be (d$x^2+d$y^2)<1.