DEFINT A-Z
MAXSIZE = 1840
DIM X(1 TO MAXSIZE)
DIM P#(1 TO MAXSIZE)
A# = 5.4110704#
B# = 9.3453409#
C# = 4.6020431#
S# = TIMER
' Create a bunch of random numbers
' between 0 and 255, and store them in an array.
FOR I = 1 TO MAXSIZE
T# = (S# * A# + B#) / C#
S# = ABS(T# - FIX(T#)) * 255
R = FIX(S#)
X(I) = R
NEXT I
' Print our random numbers in hex format
COLOR 7, 0
CLS
FOR I = 1 TO MAXSIZE
R = X(I)
IF R < 16 THEN PRINT "0";
PRINT HEX$(R);
IF N < 26 THEN N = N + 1: PRINT " "; ELSE N = 0
NEXT I
LOCATE 25, 26: PRINT "< PRESS ENTER TO CONTINUE >";
DO UNTIL INKEY$ = CHR$(13): LOOP
' Print our random numbers in raw text format
CLS
FOR I = 1 TO MAXSIZE
R = X(I)
IF R < 32 THEN PRINT " "; ELSE PRINT CHR$(R);
NEXT I
LOCATE 25, 26: PRINT "< PRESS ENTER TO CONTINUE >";
DO UNTIL INKEY$ = CHR$(13): LOOP
' Print our random numbers in binary format
CLS
FOR I = 1 TO MAXSIZE
R = X(I)
IF R AND 128 THEN PRINT "1"; ELSE PRINT "0";
IF R AND 64 THEN PRINT "1"; ELSE PRINT "0";
IF R AND 32 THEN PRINT "1"; ELSE PRINT "0";
IF R AND 16 THEN PRINT "1"; ELSE PRINT "0";
IF R AND 8 THEN PRINT "1"; ELSE PRINT "0";
IF R AND 4 THEN PRINT "1"; ELSE PRINT "0";
IF R AND 2 THEN PRINT "1"; ELSE PRINT "0";
IF R AND 1 THEN PRINT "1"; ELSE PRINT "0";
PRINT " ";
NEXT I
LOCATE 25, 26: PRINT "< PRESS ENTER TO CONTINUE >";
DO UNTIL INKEY$ = CHR$(13): LOOP
' Print our random numbers as colors
CLS
FOR I = 1 TO MAXSIZE
R = X(I)
' Here we convert each random byte into a hex number.
' We take the low digit and use it for the background color,
' and we take the high digit and use it for the foreground color.
H$ = HEX$(R)
IF R < 16 THEN H$ = "0" + H$
F = VAL("&H" + MID$(H$, 1, 1))
B = VAL("&H" + MID$(H$, 2, 1))
COLOR F, B
PRINT CHR$(177);
NEXT I
COLOR 7, 0
LOCATE 25, 26: PRINT "< PRESS ENTER TO CONTINUE >";
DO UNTIL INKEY$ = CHR$(13): LOOP
' Print our random numbers as letters
CLS
FOR I = 1 TO MAXSIZE
R = X(I)
' Here we change the top two bits of every byte
' to make sure that mostly printable letters are displayed.
R = (R AND &H3F)
R = (R OR &H40)
PRINT CHR$(R - 4);
NEXT I
LOCATE 25, 26: PRINT "< PRESS ENTER TO CONTINUE >";
DO UNTIL INKEY$ = CHR$(13): LOOP
' Print our random numbers like a stock chart
CLS
PRICE# = 10
MAXPRICE# = 0
MINPRICE# = 1000000
' Here we assume that each random number is a daily price change.
' And as the price changes, we record each new price.
FOR I = 1 TO MAXSIZE
R = X(I)
PRICECHANGE# = (R - 128) / 100
PRICE# = PRICE# + PRICECHANGE#
P#(I) = PRICE#
' We also want to know our highest price and our lowest price.
IF PRICE# < MINPRICE# THEN MINPRICE# = PRICE#
IF PRICE# > MAXPRICE# THEN MAXPRICE# = PRICE#
NEXT I
X = 0
W = 0
MAXY = 0
MINY = 25
' Our price records can go from a negative value all the way to millions,
' yet we only have 25 rows on the screen to display all that. So, here
' we're going to convert each price to a coordinate on the screen.
IF MINPRICE# < 0 THEN OFFSET# = ABS(MINPRICE#) ELSE OFFSET# = 0
FOR I = 1 TO MAXSIZE
PRICE# = (P#(I) + OFFSET#) / (MAXPRICE# + OFFSET#) * 24
Y = FIX(PRICE#)
IF Y < 1 THEN Y = 1
IF Y > 25 THEN Y = 25
W = W + 1
IF Y < MINY THEN MINY = Y
IF Y > MAXY THEN MAXY = Y
IF W = 1 THEN OPENING = Y
' No matter how much data we have, we're going to
' squeeze it all into 80 columns on the screen.
IF W > FIX(MAXSIZE / 81) THEN
X = X + 1
IF X > 80 THEN EXIT FOR
CLOSING = Y
IF OPENING > CLOSING THEN COLOR 10 ELSE COLOR 12
FOR Y = MINY TO MAXY
LOCATE Y, X
PRINT "|";
NEXT Y
W = 0
MAXY = 0
MINY = 25
END IF
NEXT I
COLOR 7, 0
LOCATE 25, 28: PRINT "< PRESS ENTER TO EXIT >";
DO UNTIL INKEY$ = CHR$(13): LOOP