home *** CD-ROM | disk | FTP | other *** search
/ Media Share 9 / MEDIASHARE_09.ISO / progmisc / euphor10.zip / DICE.EX < prev    next >
Text File  |  1993-06-17  |  790b  |  35 lines

  1.         -----------------------------------
  2.         -- roll dice and see a histogram --
  3.         -----------------------------------
  4. constant NUMBER_OF_DICE = 4
  5. constant NUMBER_OF_ROLLS = 500
  6.  
  7. function sum(sequence x)
  8. integer s
  9.     s = 0
  10.     for i = 1 to length(x) do
  11.     s = s + x[i]
  12.     end for
  13.     return s
  14. end function
  15.  
  16. procedure dice()
  17. integer s
  18. sequence total, x, roll
  19.  
  20.     total = repeat(0, 6 * NUMBER_OF_DICE)
  21.     x = repeat(6, NUMBER_OF_DICE)
  22.     for i = 1 to NUMBER_OF_ROLLS do
  23.     roll = rand(x)
  24.     s = sum(roll)
  25.     total[s] = total[s] + 1
  26.     end for
  27.     printf(1, "\t%d dice, %d rolls\n", {NUMBER_OF_DICE, NUMBER_OF_ROLLS})
  28.     for i = NUMBER_OF_DICE to 6 * NUMBER_OF_DICE do
  29.     printf(1, "%2d: ", i)
  30.     puts(1, repeat('*', total[i]) & '\n')
  31.     end for
  32. end procedure
  33.  
  34. dice()
  35.