Random points in a Triangle
An interesting and hard question asked in Quant Interview at Tower Research Capital
Before we begin this week’s Newsletter
The Puzzledquant crew has been having a blast with a new finance trivia game called Uncovered Shorts.
Uncovered Shorts sends an informative recap of each day’s quiz – sign up after playing the game. Share your results with friends through a fun snapshot and see if you can top our scores!
Now for this Week’s problem
Meet Sara, a mathematician with a special tool that generates random numbers from a uniform distribution between [0, 1]. Sara is tasked with drawing a triangle on a 2D plane with vertices at (0,0), (1,0), and (x,y). She needs to come up with an algorithm that allows her to sample points uniformly from within or on the triangle. However, she can only use the random number tool twice for each point she samples.
Question: How should Sara approach the problem to ensure all sampled points are uniformly distributed within the triangle?
Try to solve this problem yourself before moving on to the solution below
.
.
.
.
.
.
Solution
Let the random samples be m and n.
Set a=min(m,n) and b=max(m,n)
For each iteration, Sara takes two random samples, a and b, and uses them to calculate the weighted coordinates of the point.
The formulas for the coordinates are:
X=(0⋅a)+(1⋅(1−b))+((b−a)⋅x)
Y=(0⋅a)+(0⋅(1−b))+((b−a)⋅y)
Thus, every point (X_0,Y_0) sampled inside the triangle has a unique solution for a and b within the range [0, 1], ensuring uniform distribution of points within the triangle.
.
.
😃 Over to you: Were you able to solve this?
👉 If you liked this post, don’t forget to leave a like ❤️. It helps more people discover this newsletter on Substack and tells us that you appreciate solving these weekly questions. The button is located towards the bottom of this email.
👉 If you love reading this newsletter, feel free to share it with friends!
Good one