%
% ------------- Buffon needle
% estimating pi
% ---------------------------------

Pi = 3.141592653589793238462643;
trial_num = 1000000000;%10^9;
a = 1;
b = 1;
l = 1;
seed = 123456789;
%random_value = r8_uniform_01(seed);
tic
hit_num = buffon_laplace_simulate( a, b, l, trial_num, seed); 
  pdf_estimate = double(hit_num)/double(trial_num);
  if ( hit_num == 0 ),
    Pi_estimate = r8_huge;
  else
    Pi_estimate = l*(2*(a + b) - l)/(a*b*pdf_estimate);
  end 
ttt=toc;
Pi_error = abs(Pi - Pi_estimate);

fprintf('''Number of trials:'',%i\n',trial_num)
fprintf('''Pi_exact:        '',%26.24f\n',Pi)
fprintf('''Pi_estimate:     '',%26.24f\n',Pi_estimate)
fprintf('''Pi_error:        '',%26.24f\n',Pi_error)
fprintf('''Time:            '',%26.24f\n',ttt)

return
