Qm
BrainteasersJane StreetOptiver

A uniformly random point inside a circle

You have a random number generator that produces numbers uniformly between 0 and 1. You want a point that is uniformly distributed inside a disc of radius 1, meaning every region of the disc is hit with probability proportional to its area.

The obvious idea is: draw x and y, use x as the distance from the centre and 2 pi y as the angle.

  1. Why does the obvious idea fail?
  2. Fix it using the same two numbers.
  3. Describe a different method that uses rejection.
Show a hint

A ring of radius r and small thickness has area proportional to r. The obvious method treats every radius as equally likely. What distribution should the radius really have?

Your answer

Solving needs a free account

Answers, streaks and solutions unlock when you are signed in. Reading the question and the hint stays free.

Discussion

Sign in to join the discussion · reading is open to everyone

💡 Discussion rules

  1. No full solutions here. Hints and approaches only.
  2. Complexity, edge cases and intuition are the point.
  3. Interview experiences are welcome. Respect your NDAs.

Loading discussion…

Learn the concepts

The theory behind this question.

Related questions

A random chord longer than the side of the triangleBoth hands in the right half of the dialBreaking a stick into a triangleDropping needles to estimate piHow far is a random point on Earth from the North Pole?
All questions →