A Monte Carlo Simulation is a way of approximating the value of a function
where calculating the actual value is difficult or impossible. 

It uses random sampling to define constraints on the value
and then makes a sort of "best guess."

A simple Monte Carlo Simulation can be used to calculate the value for 



π


{\displaystyle \pi }

.

If you had a circle and a square where the length of a side of the square
was the same as the diameter of the circle, the ratio of the area of the circle
to the area of the square would be 



π

/

4


{\displaystyle \pi /4}

.

So, if you put this circle inside the square and select many random points
inside the square, the number of points inside the circle
divided by the number of points inside the square and the circle
would be approximately 



π

/

4


{\displaystyle \pi /4}

.



Task

Write a function to run a simulation like this, with a variable number of random points to select.

Also, show the results of a few different sample sizes.

For software where the number 



π


{\displaystyle \pi }

 is not built-in,
we give 



π


{\displaystyle \pi }

 as a number of digits:

            3.141592653589793238462643383280



 
import <Utilities/Random.sl>;
import <Utilities/Conversion.sl>;
 
main(args(2)) := monteCarlo(stringToInt(args[1]), stringToInt(args[2]));
 
monteCarlo(n, seed) :=
	let
		totalHits := monteCarloHelper(n, seedRandom(seed), 0);
	in
		(totalHits / intToFloat(n))*4.0;
 
monteCarloHelper(n, generator, result) :=
	let
		xRand := getRandom(generator);
		x := xRand.Value/(generator.RandomMax + 1.0);
		yRand := getRandom(xRand.Generator);
		y := yRand.Value/(generator.RandomMax + 1.0);
 
		newResult := result + 1 when x^2 + y^2 < 1.0 else
					 result;
	in
		result when n < 0 else
		monteCarloHelper(n - 1, yRand.Generator, newResult);
 