The number
in
th
e parentheses is called a
"dummy
variable
."
It does
not matter what number is us
ed
as
the
dummy
variable, but it
is
im-
portant that the parentheses appear and that they
enclose something
(any number or letter). For typing ease, 0 is usually placed
in
the
dummy variable position. Change line 10 again as shown below:
1.0
PRINT
(RND(O)
*
1.0)
RUN
1.0
PRINT
(RND(O)
*
1.00)
RUN
1.0
PRINT
(RND
(0)
*
1.000)
RUN
Each program generates a different range of random numbers. PRINT
(RN
D(O)
* 10) generates numbers up to 10 because the statement
in-
structs the computer to multiply the random number by 10. Multiplying
by 10 moves the decimal point over one place.
In
PRINT
(RND(O)
*
100), multiplying by 100 moves the decimal point over two places, and
in
PRINT
(RND(O)
* 1000), multiplying by 1000 moves the decimal
point over three places. If you want, you can multiply by much larger
numbers to generate large random numbers.
Because long numbers with many digits after the decimal point are
cumbersome, the computer has
an
instruction that tells it to print only
integers. Integers are whole numbers without any decimal points.
The
instruction I NT tells the computer to drop everything after the decimal
point. Reprogram the three variations of line 10 above and compare
the
results:
1.0
PRINT
INTCRNDCO)*1.0)
RUN
1.0
PRINT
INT
C
RND
(0)
*1.00)
RUN
1.0
PRINT
INTCRND(0)*1.000)
RUN
The programs generate numbers
in
the same ranges as before, but
the numbers are more
readable without the digits after the decimal.
To
generate numbers
in
a more specific range, try the examples
below:
1.0
PRINT
INT
CRND(0)*3)
RUN
1.0
PRINT
INT
CRNDCO)*1.2)
RUN
1.0
PRINT
INT
CRNDCO)*25)
RUN
51