The Generate Random Point in a Circle coding problem asks you to implement a function that returns a random point (x,y) that lies within a given circle. You are given the radius and the center coordinates (x_center,y_center). Every point inside the circle must have an equal probability of being selected (uniform distribution).
Why is this asked in interviews?
Meta and other companies use this to test your knowledge of Math, Probability, and Rejection Sampling. It evaluation whether you understand the pitfalls of uniform distribution—specifically, that simply picking a random angle and a random radius leads to more points clustering near the center. It tests your ability to use geometric properties to achieve true uniformity.
Algorithmic pattern used
There are two common solutions:
Rejection Sampling:
Generate a random point (x,y) within a square of side 2R that encloses the circle.
Check if the point is inside the circle: dx2+dy2≤R2.
If not, discard and try again. This is perfectly uniform but can take multiple attempts.
Polar Coordinates (Inverse Transform Sampling):
Pick a random angle heta in [0,2π].
Pick a random radius r by taking the square root of a random number in [0,1] and multiplying by R: r=Rimesrand(0,1). The square root is necessary to correct the area density bias.
Area Bias: Using r=Rimesrand(0,1) without the square root. This results in a distribution where points are 4x denser at the center than at the edge.
Floating Point Errors: Not using proper random float generators.
Square vs Circle: Forgetting that points in the "corners" of the bounding square are not in the circle.
Interview preparation tip
Always discuss why the naive approach (without the square root) is biased. Showing that you understand the relationship between radius and area (Area=πr2) is what separates an average candidate from a great one.