IBM 5110 Basic Introduction page 117

Table of Contents

Advertisement

c~
c
You can also include expressions inside the parentheses, for example:
INT(X
t
2+Y*12)
You might use SGN(X) to find out if X is positive:
SGN(X)
The RND function is a little different from the other functions. You can
use RND alone, without a value, to generate a random number
between 0 and 1. Each subsequent use of RND in the program will
generate a new random number. However, if you rerun the program
with a new RUN command, the random numbers generated will be the
same as the numbers generated the first time you ran the program.
To avoid this, you can use RND(X) to start different sets of random
numbers each time you run your program. The value of X is used by
the process that develops the random number. If you want a random
number that is a whole integer instead of a decimal number between 0
and 1, multiply the result of RND or RND(X) by a constant (depending
on what range you want the random numbers to have); and then use
the INT function to make the result an integer.
For example:
INT(RND*10)
Produces a random integer between 0 and 9.
INT(RND*100)
Produces a random integer between 0 and 99.
INT(RND*1000)
Produces a random integer between 0 and 999.
More Things You Can Do With BASIC
113
c~
c
You can also include expressions inside the parentheses, for example:
INT(X
t
2+Y*12)
You might use SGN(X) to find out if X is positive:
SGN(X)
The RND function is a little different from the other functions. You can
use RND alone, without a value, to generate a random number
between 0 and 1. Each subsequent use of RND in the program will
generate a new random number. However, if you rerun the program
with a new RUN command, the random numbers generated will be the
same as the numbers generated the first time you ran the program.
To avoid this, you can use RND(X) to start different sets of random
numbers each time you run your program. The value of X is used by
the process that develops the random number. If you want a random
number that is a whole integer instead of a decimal number between 0
and 1, multiply the result of RND or RND(X) by a constant (depending
on what range you want the random numbers to have); and then use
the INT function to make the result an integer.
For example:
INT(RND*10)
Produces a random integer between 0 and 9.
INT(RND*100)
Produces a random integer between 0 and 99.
INT(RND*1000)
Produces a random integer between 0 and 999.
More Things You Can Do With BASIC
113

Advertisement

Table of Contents
loading

Table of Contents