Math 242 B, 21 February 2022

piValues=salaminBrent/@Range[2]

piValues=salaminBrent/@Range[8];

$MaxExtraPrecision=10000

accuracy=N[-Log[10,Abs[Pi-piValues]],5]

ClearSystemCache[];
Timing[salaminBrent[13]][[1]]

ClearSystemCache[];
Timing[N[salaminBrent[13],11000]][[1]]

ClearSystemCache[];
Timing[salaminBrent[14]][[1]]

ClearSystemCache[];
Timing[N[salaminBrent[14],22000]][[1]]

Dart Board Approximation of π

Table[RandomReal[],10]

Module that generates m random points and uses the number that fall in the (quarter) circle to approximate pi.

dartBoard[m_]:=Module[{count=0,x,y},
Do[
(* generate a random point (x,y) *)
x=RandomReal[];
y=RandomReal[];
(*Print[{x,y}];*)

(* check if the point is in the circle *)
If[x^2+y^2<1,count+=1]
,m];

(* return value *)
4*count/m
]

dartBoard[100]

N[%]