PROGRAM MakePi (input, output);
{利用随机数函数计算Pi的值.将随机数的前后两个值(均在0-1之间)作为点的x,y坐标.
统计10000个点中,落入半径为1的四分之一圆内的点数n,从而计算出四分之一圆的面积s
(s=n/10000).又知四分之一圆的面积为Pi*r2/4 = Pi/4,由此即可算出Pi的值}
CONST
MAX = 10000;
VAR
i, n : integer;
Pi, s, seed, x, y: real;
{产生随机数的函数说明}
FUNCTION rand(VAR seed: real): real;
CONST
a = 93.0;
m = 8192.0;
c = 1.0;
BEGIN
seed:= a * seed + c;
seed:= round((seed/m - trunc(seed/m))*m);
rand:= seed/m
END;
BEGIN {主程序}
seed:= 0.7823; n:= 0;
FOR i:=1 TO MAX DO
BEGIN
x:= rand(seed);
y:= rand(seed);
IF x*x + y*y