I am trying to find the value of $\pi$ using Monte Carlo simulation. However, I don't want to generate two random numbers as coordinates. Instead, I want to select a point on the edge of the square first and select another point on the line that connects the origin and this previously selected point.
In other words, the point of this is to find the area of the circle without using x and y coordinates.
The idea is that if $a$ is a random number between 1 and $\sqrt{2}$ and then $b$ is a random number between 0 and $a$ In theory all values of $b$ that are less than 1 should be inside the circle, so I should have the number of points in the circle and the number of total points, that way I can calculate the fraction that is proportional to $\pi$.
I wrote the following Python code to achieve that but I get results close to $3.4$ instead of the real value of $\pi$. I asked the question on Stack Overflow and they said the issue is not about the program itself but the way I am trying to find the value. Is there a flaw in my reasoning?
Here's the code I used:
$\pi$ Monte Carlo
import random
import pylab
def MonteCarloPI(numtries):
circle = 0
for i in range (numtries):
a = (float(random.random())+1)**0.5
b = float(random.random())*a
if b <= 1:
circle += 1
rapportoAree = (circle/numtries)
return rapportoAree*4
print(MonteCarloPI(1000))