'\begin{verbatim} 'Simulating N fair coins ' declarations DECLARE FUNCTION NumHeads% (p!, n%) DEFINT I-N ' declare integer variables 'prepare screen CLS PRINT "Simulating toss of n fair coins" 'get users input n = 10 'number of trials INPUT "Number of coins n=", n pr = .5 ' fairness of a coin frac = .8 ' percentage of heads seeked ' get the frac from the user PRINT " How often we get more than f heads? (where 0 frac * n THEN s = s + 1 IF INKEY$ > "" THEN EXIT DO LOCATE 10, 10 PRINT "Trial #"; T PRINT "Current estimate"; USING "##.#####"; s / T LOOP 'print the answer PRINT PRINT "Prob of more then "; INT(frac * n); " heads in "; n; " trials is about "; s / T END DEFINT A-H, O-Z FUNCTION NumHeads (p!, n) 'simulate a run of n coins h = 0 FOR k = 1 TO n IF RND(1) < p! THEN h = h + 1 NEXT k NumHeads = h '\end{verbatim} END FUNCTION