246 Programming
MAKELIST(0,X,1,2*sides,1) L2;
FOR k FROM 1 TO n DO
ROLLDIE(sides)+ROLLDIE(sides) roll;
L2(roll)+1
L2(roll);
END;
END;
ROLLDIE(n)
BEGIN
RETURN 1 + FLOOR(n*RANDOM);
END;
In this scenario, assume there is no ROLLDIE function
exported from another program. Instead, ROLLDIE is
visible only in the context of ROLLMANY.
Finally, the list of results could be returned as the result of
calling ROLLMANY instead of being stored directly into
the global list variable, L2. This way, if the user wanted
to store the results elsewhere, it could be done easily.
EXPORT ROLLMANY(n,sides)
BEGIN
LOCAL k,roll,results;
MAKELIST(0,X,1,2*sides,1)
results;
FOR k FROM 1 TO n DO
ROLLDIE(sides)+ROLLDIE(sides)
roll;
results(roll)+1
results(roll);
END;
RETURN results;
END;
On the Home screen, you would enter
ROLLMANY(100,6)
L5 and the results of the
simulation of 100 rolls of two six-sided dice would be
stored into list L5.