Frequency Histogram

Developer(s): Martin Oakes
Date: 1981
Type: Program
Platform(s): ZX80

Answer CELLS? with the number of values to test (up to 20) and LOOPS with how many random numbers to draw. The program calls RND that many times, counts how often each value comes up and prints a bar of graphic blocks for each, scaled to fit, with the totals and scale below.

The article admits one deliberate limit: asking for 20 cells and 3000 loops fills the display and crashes. It also says a comma at the end of line 80 keeps the bars lined up; the printed line 80 has no comma (the printed Syntactic Sum includes it), so bars for two-digit cells start one place further right.

Published in Syntax May 1981 (Frequency Histogram).

Related Articles

Program tests how random the ZX80/MicroAce's random number generator really is.

Image Gallery

Source Code

  10 PRINT "CELLS?"
  12 INPUT N
  14 IF N>20 THEN LET N=20
  15 PRINT "LOOPS"
  16 INPUT L
  17 CLS
  20 DIM A(20)
  30 FOR I=1 TO L
  40 LET J=RND(N)
  50 LET A(J)=A(J)+1
  60 NEXT I
  62 LET S=1
  63 FOR I=1 TO N
  64 IF A(I)<24 THEN GO TO 66
  65 LET S=A(I)/24+1
  66 NEXT I
  70 FOR I=1 TO N
  75 IF I<10 THEN PRINT " ";
  80 PRINT I; "="; A(I)
  90 LET M=A(I)/S
 100 IF M>24 THEN LET M=24
 110 FOR K=1 TO M
 120 PRINT "▄";
 130 NEXT K
 140 PRINT
 150 NEXT I
 155 PRINT "NUM=";N,"LOOPS=";L,"SCALE=";S
 160 STOP

Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.