home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Media Share 9
/
MEDIASHARE_09.ISO
/
progmisc
/
euphor10.zip
/
DICE.EX
< prev
next >
Wrap
Text File
|
1993-06-17
|
790b
|
35 lines
-----------------------------------
-- roll dice and see a histogram --
-----------------------------------
constant NUMBER_OF_DICE = 4
constant NUMBER_OF_ROLLS = 500
function sum(sequence x)
integer s
s = 0
for i = 1 to length(x) do
s = s + x[i]
end for
return s
end function
procedure dice()
integer s
sequence total, x, roll
total = repeat(0, 6 * NUMBER_OF_DICE)
x = repeat(6, NUMBER_OF_DICE)
for i = 1 to NUMBER_OF_ROLLS do
roll = rand(x)
s = sum(roll)
total[s] = total[s] + 1
end for
printf(1, "\t%d dice, %d rolls\n", {NUMBER_OF_DICE, NUMBER_OF_ROLLS})
for i = NUMBER_OF_DICE to 6 * NUMBER_OF_DICE do
printf(1, "%2d: ", i)
puts(1, repeat('*', total[i]) & '\n')
end for
end procedure
dice()