EasyManua.ls Logo

Radio Shack TRS-80 - Page 102

Radio Shack TRS-80
236 pages
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
RUN
it a few
times to get
the
idea.
Let's put a
semi-colon
behind our PRINT
statement so
we can
get
more numbers on the
screen at
one
time,
and
increase
our
FOR-NEXT loop
to
90
passes.
Change
your program
accordingly
:
40
FDR N
=
1
TD 90
50
PRINT
RND(0)
j
60
NEXT
N
. . .
and RUN.
You get
the idea.
Are
yoi*
using B, now
instead
of
RUN? Sure
is
easier; isn't it?
This is
fairly exciting!
Well,
maybe so,
hut you
ain
't seen nothing yet!
Virtually
all computer games
are
based on
the RND(X)
function,
and
you'll soon
be playing some and
designing your own.
RND(X) with racing
stripes.
The RND(0)
we
just
experimented
with
is the
traditional
Random
Number
Generator. In
other BASIC
dialects you may
see it written as
just plain RND.
With
a little
mathematical
chicanery
and use
of
the INT
function it
is possible to
turn
those numbers
between
and 1
into
something
useful. Rather
than study that
technique,
however, let's look
at the Radio
Shack
upgrade which does
it
all so much
easier.
Change line
50
to read
:
50
PRINT
RND(
15
)
;
. . . and
RUN
.
Wow!
That's more
like it
real
live random
integers.
And they all are
values
that fall
between 1
and 15. Figured
it out already?
Pretty simple,
isn't it?
1.
If the
number
in
parentheses
(or its INT
value)
is
0,
the
numbers
generated are between
Q and 1
.
2.
If the
number in
parentheses is 1
or
larger, the
numbers generated
are
from
1
to
the INT value
of
that
number
(inclusive).
3.
In LEVEL I
BASIC, the
largest
permissible
value of X is
32767.
Skeptical?
You don't
believe the
numbers
are really
random?
You
want
proof?
A
natural
reaction. OK
how about
pretending to
repeatedly
flip
a coin and
see
how
many heads come up
compared
to the number of
tails?
100
..'-'~-<
-v."-
1
--
1
--
W^re |ust
trying:
to
tell you
that
"ours"
is
better,
than "theirs".
With Radio
Shack's Random
Number
Generator
we
<^a
come up
with
all
th*
numbers
without
all that fancy footwork.

Other manuals for Radio Shack TRS-80

Related product manuals