Random point in a circle
You’re given a procedure that with a uniform probability distribution outputs random numbers between 0 and 1 (to some sufficiently high degree of precision, with which we need not concern ourselves in this puzzle). Using a bounded number of calls to this procedure, construct a procedure that with a uniform probability distribution outputs a random point within the unit circle.
The problem does not state whether the random number is inclusive, exclusive or some combination, of the bounds 0 and 1. My answer assumes the typical random number generator, which is inclusive of 0 and exclusive of 1. It takes exactly two calls to the random number generator.
radius = random / 2
degrees = random * 360
x = radius * sin(degrees)
y = radius * cos(degrees)
Now the problem with this solution is that it lacks uniform distribution. Half the points will have radius < 0.25 and half 0.25 to 0.5, but the area in the circle with radius < 0.25 is only 25% of the total area of the circle. So we need to distribute the points along the radius using the inverse square of the random value so that the probability of a point having radius r is proportional to the area of a circle with radius r (i.e. a radius that gives a circle with area a is half as likely as a radius that gives a circle with area 2a).
radius = sqrt(random) / 2
degrees = random * 360
x = radius * sin(degrees)
y = radius * cos(degrees)
Your Answer
More puzzles to try-
Moving right to left riddle
What are moving right to left, right now?Read More »What letter is missing From the center
Ages of Daughters
Christina, Allison and Lena are 3 daughters of John a well-known Mathematician, When I asked John the age of their ...Read More »Do you see two faces or a vase?
Do you see two faces or a vase? opRead More »FIND POISONED BOTTLE ELSE DIE
You are the ruler of a medieval empire and you are about to have a celebration tomorrow. The celebration is ...Read More »School time riddle
A boy leaves home in the morning to go to school. At the moment that he leaves the house, he ...Read More »What does the picture indicates?
Dead without Reason
A person was found dead on a big green land with no trees or buildings around. When the police arrived, ...Read More »Decrypt Name of software company in this picture
Can you Decrypt the name of a software company in this picture? Only If you decrypted the name correctly within ...Read More »Find Age code
If Bihan is 10, Anirudha is 20, and Kim and Seal are both 5, but Rikold is 10, how much ...Read More »2 cold and 2 fever tablet mix puzzle
If I give you 4 tablets which contain 2 for fever and 2 for cold..all 4 have same size, shape ...Read More »How many squares, of any size, can you find on this chess board which do not contain a Rook?
Rearrange the letters in “new door” to make one word.
Rearrange the letters in “new door” to make one word.Read More »Tell the word
whats is 3/7 chicken, 2/3 Cat , 1/2 Goat..?Read More »Cage and Canary Riddle
If I put in one canary per cage, I have one bird too many. If I put in two canaries ...Read More »Puzzle in a Puzzle
What are the next two letters in the following series and why? W A T N T L I T ...Read More »Soft and Cuddly
I am soft and cuddly that soothe your heart. But, If you pick my last name I am going to ...Read More »Fisherman riddle
A fisherman decided to become a golfer. In order to buy his membership he had to sell his boat. How ...Read More »Crack the Glass
If boiling water is poured into a thick glass as well as a very thin glass, which is more likely ...Read More »What happened?
Two men are facing each other alone in a large room. There is a clock on the wall. One man, ...Read More »