# # The program that approximates the probability of # throwing two points into a 1x1 square, having distance # less than r # two_pts:=proc( r::numeric, n::integer ) local x1, y1, x2, y2, i, count, dist; count:=0; for i to n do # simulation # the first point x1:=real_ran(0,1); y1:=real_ran(0,1); # the second point x2:=real_ran(0,1); y2:=real_ran(0,1); # testing and counting dist:=sqrt((x1-x2)^2+(y1-y2)^2); if dist < r then count:=count+1; fi; od; evalf( count/n ); end; # # function that output a random real number in [a,b] # real_ran:=proc( a::numeric, b::numeric ) local x; x:=rand(); evalf( a+ (b-a)*x/999999999999 ); end;