Skip to content
Game 5 Unit 2 of 5 1 hr learning time

Counting the Faces

Six counters and a chain of IFs turn a hundred rolls into a tally — the accumulation pattern at the heart of the simulation.

40% of Dice Roller

Rolling a hundred dice takes one change — the loop to 1 TO 100. The new idea is remembering what came up. To see whether a die is fair, you need to count how many times each face appears. That means six running totals, nudged up one at a time as the dice land.

  10 BORDER 0: PAPER 0: INK 7: CLS
  20 RANDOMIZE
  60 CLS
  70 LET t1 = 0: LET t2 = 0: LET t3 = 0
  80 LET t4 = 0: LET t5 = 0: LET t6 = 0
  90 PRINT "Rolling 100 dice..."
 100 PRINT
 110 FOR i = 1 TO 100
 120 LET d = INT (RND * 6) + 1
 130 IF d = 1 THEN LET t1 = t1 + 1
 140 IF d = 2 THEN LET t2 = t2 + 1
 150 IF d = 3 THEN LET t3 = t3 + 1
 160 IF d = 4 THEN LET t4 = t4 + 1
 170 IF d = 5 THEN LET t5 = t5 + 1
 180 IF d = 6 THEN LET t6 = t6 + 1
 250 NEXT i
 260 PRINT "1: "; t1; "  2: "; t2; "  3: "; t3
 270 PRINT "4: "; t4; "  5: "; t5; "  6: "; t6
Black ZX Spectrum screen: Rolling 100 dice... above two lines of totals, 1: 17 2: 12 3: 24 and 4: 15 5: 13 6: 19
A hundred rolls, counted: the six totals sum to 100, close to even but not exact.

The accumulation pattern

Lines 70–80 set up six counters, t1 to t6, all starting at zero. Inside the loop, lines 130–180 are a chain of IFs: whichever face came up, that counter gains one — IF d = 1 THEN LET t1 = t1 + 1, and so on. LET t1 = t1 + 1 reads as "make t1 one bigger than it is now"; the counter remembers its value between rolls and grows across the whole run.

That is accumulation — a value that builds up over many passes of a loop. You met it as a single counter in Reflex's reaction timer; here it is six counters working in parallel, one per outcome. It is the pattern behind every score, every total, every statistic a program keeps.

A hundred is not enough either

The totals come out close to even — around 16 or 17 each — but not exact, and the gaps look large. Is face 3 truly better than face 2, or is a hundred rolls just too few to tell? You already suspect the answer: roll more. But staring at the screen while a thousand dice land, then reading six final numbers, is a poor way to watch. The totals deserve to be seen as they climb.

Next: a dashboard that updates as each die lands.