Range formula
as
used in line 127
Note
that
the program runs more slowly
as
it nears the
52nd
number and
is
especially
slow
on the last card; this
is
because it has
to
fetch more and more ran-
dom
numbers to find one
that
has not already been picked. A simple routine such
as
this has much raom
for
improvement,
of
course.
It
can
be
speeded up just by
finding the last number
in
the program
fram
the table rather than randomly
A
further
example
of
RND
use illustrates the difference
in
having a faster
selection routine. This program also handles random numbers larger than the
integer range allows.
The
following
program
is
a modification of program BLANKET. the display
program developed in Chapter
3.
Instead of printing the display character in con-
tinuous-line format. this pragram fills the screen by
randomly
POKEing the
character into the 1000 positions of the screen.
Here
is
the first version.
10
REM
****.**
B
LAN
K E T .*.**
••
20
REM
RANDOM
DISPLAY
OF
ONE
30
REM
CHARACTER
ENTERED
FROM
THE
40
REM
KEY
BOARD
50
REM
**.***
•••
**
••••••••••••••••••••
9(1
PRIt-IT"HIT A
KE'T'
OR
<R>
TO
Et-.lD".;
10(1
GET
C$: 1F
C$=""
GOTO
100
105
IF
C$=CHR$(13)
GOTO
170
110
PF~
1
tH
";1"
.;
:
REI't
CLEAR
SCREEt-I
120
X=RND(-TI)
:REM
START
NEW
SEED
125
C=(ASC(C$)A~m128),)2
OR
(ASC(C$)AND63)
127
A=1000*RND(1)+32768
130
POKE
A,C
:REM
DISPLAY
CHAR
140
GET
D$:IF
D$=""
GOTO
127
150
C$=D$
1
6(1
GOTO
105
17(1
Et·m
The program
is
the standard BLANKET program through line 110.
inputting
a new character and clearing the screen. Line 120 stores a new seed
in
prepara-
tion for a random display sequence on the screen. Line 125 converts
C$
to
its
equivalent
POKE
number
as
in BLANKET Program 10
(see
Appendix
Cl.
Line 127
calculates a random screen address in the range
32768
to 33767; using the
RND
range formula
with
m=32768
and
n=33767.
line 127 was derived
as
follows:
(n~m+1)*RND(1)+m
(33767
-32768+
1)*RND(l
)+32768
=1
OOO*RND(l
)+32768
Neither the INT
function
nor an integer variable (which
would
have been
A%)
can
be
used. because the screen addresses begin
just
beyond the
maximum
integer value of 32767. Fortunately the
POKE
function.
which
is
where the screen
addresses
will
be
used.
simply
discards any fractional portion of a real number ad-
dress presented to il. (For other applications
when
vou are dealing
with
random
numbers outside the integer range.
Vou
will
have to check
that
the floating
point
equivalent provides the intended range.)
297