Sample uniformly from a circle’s area

Read the full interview experience this question came from →

Quick Overview

This question evaluates understanding of continuous probability distributions and geometric random sampling, testing whether a candidate recognizes how area-weighted uniformity differs from naive radial choices.

Sample uniformly from a circle’s area

Company: LinkedIn

Role: Machine Learning Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Onsite

How would you generate a point `(x, y)` uniformly at random from the *area* of a circle of radius `R` centered at the origin? - Explain why naive choices (e.g., choosing radius uniformly in `[0,R]`) are not uniform over area. - Provide a correct sampling method (math + pseudocode).

Overview: This question evaluates understanding of continuous probability distributions and geometric random sampling, testing whether a candidate recognizes how area-weighted uniformity differs from naive radial choices.

Read the full LinkedIn Machine Learning Engineer interview experience this question came from

Community answers

Answer by Cuckoo

I first choose a random angle uniformly from 0 to 2π. I cannot choose the radius uniformly because outer rings have more area. I use r = R * sqrt(U) to compensate for the increasing area as the radius gets larger. Then I convert from polar coordinates to x and y. r = R * sqrt(random()) theta = 2 pi random() x = r * cos(theta) y = r * sin(theta)

Answer by Cuckoo

Another solution is Rejection sampling. Suppose we have a square around the circle whose length of each side is 2R. Now, we generate numbers between 0 and 2R for x an y and every point has the same chance to get selected. Then if the selected point is inside the circle, x2 + y**2 < R, we accept it otherwise generate another number. The chance of success in this experiment is piR2/4R**2
|Home/Coding & Algorithms/LinkedIn
LinkedIn logo
LinkedIn
Feb 18, 2026
mediumMachine Learning EngineerOnsiteCoding & Algorithms
25
0

How would you generate a point (x, y) uniformly at random from the area of a circle of radius R centered at the origin?

  • Explain why naive choices (e.g., choosing radius uniformly in [0,R] ) are not uniform over area.
  • Provide a correct sampling method (math + pseudocode).

Submit Your Answer to Earn 20XP

Sign in to leave a comment

Loading comments...