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-
Tricky addition riddle
20+20+20=60. How can you make 60 again by using the same number 3 times, but it can’t be 20?Read More »Water and Milk in one barrel riddle
You have a glass of water and a glass of milk. You need to empty the two liquid into a ...Read More »The Death Statemant
Once a man was caught for a minor offense and was presented in king Akbar’s darbaar Akbar wanted to test ...Read More »Black or Brown Gloves
Mr. Brown has 8 black gloves and 8 brown gloves in his closet. He blindly picks up some gloves from ...Read More »French Fun
Christina has four classes, Science, Math, English, and History. She had a test in every class, and wanted to have ...Read More »Best and Cheapest
What is the best and cheapest light?Read More »Dr. Willam and surgical gloves puzzle
Dr.Willam wants to operate for three different persons who were wounded. But he had only two surgical gloves. There is ...Read More »Jacob and Magician Riddle
Jacob went with his girlfriend Melony in a magic show. At the start of the show, the magician tells the ...Read More »Millions year old
It has been around for millions of years, but it is no more than a month old. What is it?Read More »Light makes strange
Different colors of lights make him strange, Consequently into different sizes he gets changed. Who is he?Read More »What am I puzzle
I am a protector. I Sit on a bridge. One individual can see directly through me , while others wonder ...Read More »Robbery Ridle
The Bank of Mexico is abducted by 5 masked strangers. One of the strangers asked the teller to give them ...Read More »Right Hands puzzle
What can you hold in your right hand, but not in your left hand?Read More »Dropping eggs
There’s a certain kind of egg about which you wonder: What is the highest floor of a 36-story building from ...Read More »Which statement is true?
Which statement is true out of the following? One statement here is false. Two statements here are false. Three statements ...Read More »Keyboard Words
Keyboard words are not in alphabetical order, Why?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 »End of life and love
It is the beginning of enmity; the end of life and love; honey can’t be without it; yet sugar can ...Read More »Tossing old gold coin puzzle
Two men find an old gold coin and want to have a coin toss with it to decide who gets ...Read More »What is highest number of apples you can get to Bananaville?
You have been given the task of transporting 3,000 apples 1,000 miles from Appleland to Bananaville. Your truck can carry ...Read More »