'\begin{verbatim} 'declarations DECLARE FUNCTION Integrand! (X!, Y!) DECLARE FUNCTION InDomain! (X!, Y!) CONST True = -1 ' simulation loop NumTrials = 10000 FOR j = 1 TO NumTrials 'select random points from the square [-1,1]x[-1,1] X = 2 * RND(1) - 1 Y = 2 * RND(1) - 1 'check if this is in the domain IF InDomain(X, Y) THEN NumTested = NumTested + 1 Sum = Sum + Integrand(X, Y) Var = Var + Integrand(X, Y) ^ 2 END IF NEXT j 'Print the answer PRINT "Examined "; NumTested; " random points" IF NumTested = 0 THEN END 'nothing found N = NumTested PRINT "The integral is approximately "; Sum / N PRINT "With 95% confidence the error is less than "; 1.96 * SQR(Var / N - (Sum / N) ^ 2) / SQR(N) END FUNCTION InDomain (X, Y) 'This function checks if $x,y$ is in the integration domain 'The definition of the domain can be easily modified here, including 'more complicated domains IF X ^ 2 + Y ^ 2 < 1 THEN InDomain = True END FUNCTION FUNCTION Integrand (X, Y) 'This is the function to be integrated Integrand = COS(10 * X + 20 * Y) '\end{verbatim} END FUNCTION