The program generates random numbers that are always one less
than the number by which it is multiplied. The first line 10 generates
the numbers 0, 1, and 2. To generate random numbers 0, 1, 2, and 3,
the program would be written this way:
10 PRINT INT ( R N D ( 0 ) * 4 )
RUN
To generate only the numbers 1, 2, and 3, the program should look
like this:
10 PRINT INT ( R N D ( 0 ) * 3 ) + 1
RUN
To generate three numbers starting at 20, write the program this way:
10 PRINT INT ( R N D ( 0 ) * 3 ) + 2 0
RUN
Random Number Game
Random-number programs are very flexible. You can even use them to
play games with your computer. Type the following program.
Remember that to get the bent arrow in line 5, press
or
NEW
1 REM *** NUMBER.GAM ***
5 PRINT "
"
10 SECRETNUM=INT(RND(0)*3)+1
20 PRINT: PRINT "I AM THINKING OF A N U M B E R , EITHER 1, 2,
OR 3 . TRY TO GUESS IT . "
30 INPUT GUESS
40 IF GUESS=SECRETNUM THEN PRINT "YOU WON. "
50 IF GUESS<>SECRETNUM THEN PRINT "YOU LOST. "
60 GOTO 10
Line 10 assigns the random number to the numeric variable called
SECRETNUM. Line 30 lets the user type in a guess and assigns this
number to the numeric variable called GUESS. (Remember that
numeric variables do not need to be dimensioned or tagged at the end
the way that string variables do.) Line 40 compares the guess to the
secret number. If they equal each other, the computer prints "YOU
WON." Line 50 also compares the guess to the secret number. If they
are not equal (the symbols < > mean not equal to), the computer prints
"YOU LOST." Line 60 makes a loop so that you can play the game
again. (The next chapter explains IF-THEN statements in more detail.)
, and press
52
, hold down
Need help?
Do you have a question about the 65XE and is the answer not in the manual?