program Buffon2 { Buffon's Needle; www.merlyn.demon.co.uk >= 2001-08-29 } ; { NOTE : This is a better demonstration; Pi is not used either explicitly or implicitly } var U, V, W : longint ; X, Y, Z : extended ; BEGIN ; W := 1000000 ; Write('Buffon2 ', W, ' ... ') ; V := 0 ; Randomize ; for U := 1 to W do begin { Generate a random point in the unit circle : } repeat X := Random ; Y := Random ; Z := Sqr(X)+Sqr(Y) until Z<1 ; { Scale to init length, and see if high enough : } if Y/Sqrt(Z)>Random then Inc(V) ; end ; Write('"Pi" : ', 2.0/(V/W):0:6, ' ') ; Readln ; END.