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

Your Own Experiment

INPUT puts the roll count in the player's hands, and a centred title makes it look built. Ten rolls or ten thousand — the choice is theirs.

80% of Dice Roller

So far the roll count is baked in — 500, every time. The simulation gets far more interesting when you set it: ten rolls to see the noise, ten thousand to see it vanish. That is one INPUT, the keyboard read you have used since Story Builder.

  10 BORDER 0: PAPER 0: INK 7: CLS
  20 RANDOMIZE
  30 LET a$ = "*** DICE ROLLER ***": LET y = 3: GO SUB 9000
  40 PRINT
  50 INPUT "How many rolls? "; n
  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 "; n; " dice..."
 100 PRINT
 110 FOR i = 1 TO n
 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
 190 PRINT AT 2, 3; t1; "  "
 200 PRINT AT 3, 3; t2; "  "
 210 PRINT AT 4, 3; t3; "  "
 220 PRINT AT 5, 3; t4; "  "
 230 PRINT AT 6, 3; t5; "  "
 240 PRINT AT 7, 3; t6; "  "
 250 NEXT i
 260 STOP

9000 PRINT AT y, (32 - LEN a$) / 2; BRIGHT 1; a$
9010 RETURN
Black ZX Spectrum screen: a column of six totals — 21, 14, 27, 17, 18, 23 — from a 120-roll run the player chose
120 rolls, because the player asked for 120 — the experiment is theirs to set.

A number from the player

Line 50 — INPUT "How many rolls? "; n — prints the prompt and reads a number into n. Earlier games read text into a string like name$; here the answer is a number, so it goes into a plain numeric variable. Line 110 then loops FOR i = 1 TO n instead of a fixed count: the program rolls exactly as many times as the player asked.

A title, written once

Line 30 calls a subroutine you wrote in Oracle Stone: GO SUB 9000 centres the title with PRINT AT y, (32 - LEN a$) / 2. The width arithmetic is already solved, so the title sits dead-centre for free. Line 260's STOP ends the run cleanly before the subroutine at line 9000, so the program never falls into it by accident.

Run it with 10, then 100, then 1000. At ten, the totals are lopsided — randomness looks random. By a thousand, they are nearly level. You are not changing the dice; you are changing how much evidence you gather. That is the experiment.

Next: turn those totals into a picture.