-- A V Peterson 20-04-2001 -- 08-04-2002 add print_stats class DIE -- The throw of a die is simulated using a random number generator -- started with a specified seed in order to allow repeatable tests. creation make feature rand : STD_RAND -- each die has its own random number generator last_value : INTEGER -- the most recent value on the die stats : ARRAY[INTEGER] -- die statistics make( seed : INTEGER ) is do -- create random number generator !!rand.with_seed(seed) -- initialise stats array !!stats.make(1,6) end -- make throw is -- Use random number generator to generate value in range 1 .. 6 local do rand.next last_value := rand.last_integer(6) -- keep die statistics stats.put(stats.item(last_value) + 1, last_value) ensure (last_value >= 1) and (last_value <= 6) end -- throw print_stats is -- Print the die statistics local i : INTEGER do io.put_string("%NDice Statistics%N") from i := stats.lower until i > stats.upper loop io.put_integer(i) io.put_integer_format(stats.item(i), 4) io.put_new_line i := i + 1 end -- loop end -- print_stats end -- class DIE