“10 PRINT” in PostScript

Back in May, I posted a LaTeX document using TikZ to implement the Commodore 64 BASIC program:

10 PRINT CHR$(205.5+RND(1)); : GOTO 10

The amusement factor (for me) is due to LaTeX’s ability to generate pseudorandom numbers, which may be surprising to some, especially those who think of LaTeX documents as static (deterministic) documents and not computer programs.

PostScript can also generate pseudorandom numbers, and hence I present “10 PRINT” in PostScript:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
%!

% Implementation of "10 PRINT" in PostScript
% Christopher Phan, cphan@chrisphan.com
% 2019-02-17

% Draw frame around page

newpath
  36 36 moveto % 36 pt = 0.5 in
  36 756 lineto % 756 pt = 10.5 in
  576 756 lineto % 576 pt = 8 in
  576 36 lineto
  closepath
stroke

% each slash will occupy a 0.25 in x 0.25 in square

36 18 558 { % 18 pt = 0.25 in
  /x exch def
  36 18 738 {
    /y exch def
    newpath
      /u rand 2 mod 18 mul def
      x y u add moveto
      x 18 add y 18 u sub add lineto
    closepath stroke
  } for
} for

showpage

Example output: