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



INCLUDE "H6:REALMATH.ACT"
 
DEFINE PTR="CARD"
DEFINE REAL_SIZE="6"
BYTE ARRAY realArray(1536)
 
PTR FUNC RealArrayPointer(BYTE i)
  PTR p
 
  p=realArray+i*REAL_SIZE
RETURN (p)
 
PROC InitRealArray()
  REAL r2,r255,ri,div
  REAL POINTER pow
  INT i
 
  IntToReal(2,r2)
  IntToReal(255,r255)
 
  FOR i=0 TO 255
  DO
    IntToReal(i,ri)
    RealDiv(ri,r255,div)
    pow=RealArrayPointer(i)
    Power(div,r2,pow)
  OD
RETURN
 
PROC CalcPi(INT n REAL POINTER pi)
  BYTE x,y
  INT i,counter
  REAL tmp1,tmp2,tmp3,r1,r4
  REAL POINTER pow
 
  counter=0
  IntToReal(1,r1)
  IntToReal(4,r4)
 
  FOR i=1 TO n
  DO
    x=Rand(0)
    pow=RealArrayPointer(x)
    RealAssign(pow,tmp1)
 
    y=Rand(0)
    pow=RealArrayPointer(y)
    RealAssign(pow,tmp2)
 
    RealAdd(tmp1,tmp2,tmp3)
 
    IF RealGreaterOrEqual(tmp3,r1)=0 THEN
      counter==+1
    FI
  OD
 
  IntToReal(counter,tmp1)
  RealMult(r4,tmp1,tmp2)
  IntToReal(n,tmp3)
  RealDiv(tmp2,tmp3,pi)
RETURN
 
PROC Test(INT n)
  REAL pi
 
  PrintF("%I samples -> ",n)
  CalcPi(n,pi)
  PrintRE(pi)
RETURN
 
PROC Main()
  Put(125) PutE() ;clear the screen
 
  PrintE("Initialization of data...")
  InitRealArray()
 
  Test(10)
  Test(100)
  Test(1000)
  Test(10000)
RETURN