Skip to content

Compare shares

Read proportions without losing the exact counts.

  • The Craft

A count needs a total beside it. Six occurrences out of twelve is half the sample; six out of sixty is one tenth. Add percentages so samples of different sizes will be comparable later.

Continue from Keep the tallies. This stage still uses twelve rolls and a final table; the new column shows each face’s share.

Replace lines 1030, 1080, 1120, 1130. There are no lines to delete.

changes.bas
1030 PRINT AT 4,1; INK 5;"FACE  COUNT   NOW%"
1080 NEXT j: PRINT AT 18,1;"Fair model: about 16.7% each."
1120 LET row=5+2*(j-1): LET pc=INT (1000*t(j)/n+0.5)/10
1130 PRINT AT row,7;t(j);"    ";AT row,15;pc;"   "
Complete program at this stage
dice-roller.bas
  10 BORDER 0: PAPER 0: INK 7: BRIGHT 0: CLS
  20 RANDOMIZE : DIM t(6)
  30 LET n=0: LET b=12
 440 FOR i=1 TO b
 450 LET d=INT (RND*6)+1: LET t(d)=t(d)+1: LET n=n+1
 460 PRINT i;": ";d
 490 NEXT i
 600 GO SUB 1000: GO SUB 1100
 750 STOP
1000 CLS : PRINT AT 0,9; INK 5; BRIGHT 1;"DICE ROLLER"
1030 PRINT AT 4,1; INK 5;"FACE  COUNT   NOW%"
1040 FOR j=1 TO 6: LET row=5+2*(j-1)
1050 PRINT AT row,2;j
1080 NEXT j: PRINT AT 18,1;"Fair model: about 16.7% each."
1090 RETURN
1100 PRINT AT 1,1;"Rolls ";n;"   "
1110 FOR j=1 TO 6
1120 LET row=5+2*(j-1): LET pc=INT (1000*t(j)/n+0.5)/10
1130 PRINT AT row,7;t(j);"    ";AT row,15;pc;"   "
1160 NEXT j
1180 RETURN

RUN. A count of three must show 25 in the NOW% column. A count of zero must show zero. Read the column heading as the percent sign for every entry.

Divide before comparing

t(j)/n is the fraction of counted rolls belonging to face j. Multiplying by 100 turns that fraction into a percentage. We round to one decimal place so the result fits in the table:

INT (1000*t(j)/n+0.5)/10

Multiplying the proportion by 1,000 gives tenths of a percentage point. Adding 0.5 and rounding down selects the nearest whole tenth; dividing by ten gives the displayed percentage. All counts are nonnegative, which is the range for this rounding rule. The Spectrum may print 25 rather than 25.0; they mean the same share.

For one out of twelve, the displayed result is 8.3%. The count is still exactly one. Rounding changes the presentation, not the tally stored in the array.

Suppose every face appears twice in twelve rolls. What happens when you add the six displayed percentages?

Show the explanation

Each is shown as 16.7%. Six times 16.7 is 100.2%, even though the exact shares sum to 100%. Separate rounding caused the difference. Do not alter a tally or quietly adjust one percentage to make the displayed total come out neatly.

A reference, not a promise

For a fair six-sided die, each face has probability one sixth, about 16.7%. The reference below the table describes that model. It does not say each face must take exactly one sixth of this particular sample.

RUN several times and compare the tables. Twelve rolls can produce a visibly uneven spread. A balanced sample would not prove the generator fair, just as one uneven sample would not prove it unfair.

The program never divides by zero: line 600 runs after the twelve-roll loop. Keep that order in mind when we move the same calculation inside the loop. We must count a roll before calculating its share.

If a displayed percentage looks wrong, divide that row’s count by the total at the top and multiply by 100. Check the arithmetic before drawing a conclusion about randomness.

Sources

Steven Vickers, edited by Robin Bradbeer, ZX Spectrum BASIC Programming, second edition (Sinclair Research, 1983), chapter 10, chapter 11.