%edgpisim.m/created by PJNahin for "Duelling Idiots"(10/22/98)
%This m-file estimates pi by randomly tossing darts at the
%unit square and counting how many land inside a quarter-
%circle with unit radius contained in the square.
%  
% This program was adapted to test the applicability of Theorem
% 5.3.2 to estimate n for Monte Carlo trials. See HO13-MCTrials.pdf

rand('state',100*sum(clock))  %set new seed for generator;
                              %initialize number of darts
                              %inside quarter-circle region;
Trials=7299;
kount=0;
for j=1:Trials
    x=rand(2,1036);
    x=x.^2;
    darts=sum(sum(x)<1);
    pi_estimate=4*darts/1036;
    if abs(pi_estimate-pi)>=0.1
        kount=kount+1;
    end
end
p=kount/Trials
disp('Applying Theorem 5.3.2,')
disp('this estimate has a 95% probability of being within 0.005 of 0.05') 
                                                             