Commodore 2001-8 User Manual page 34

Table of Contents

Advertisement

A number greater than that will result in an overflow. A form of the expression is EXP(X). Although the PET
only allows the flow function for E, other functions are available by ratioing to the Log:
?EXP(1)
Basic logrithmic function is given with the parameter LOG(X) which is logged to base E.
To calculate the LOG to base 10, the expression is written:
LOG(X)/LOG(10)
RANDOM
The random functions are useful for many statistical programs and games. Basic random functions are
provided. The random number generator uses an algorithm which develops a value between zero and one.
The argument can be either non-zero, or negative. Positive numbers always return the next value of the
random number sequence generated by a numerical algorithm in BASIC. It always starts with the same
value, or seed power-on. However, the seed for the random can' be initialized by using the minus value.
Repetitive access to the random function in a program is not random because the relationship of the time
is predictable from the time that the program is initialized. So in a fixed program sequence, the only truly
random number is the first one. A solution to this is to use the time to generate random seed, use the
RND( - TI) to seed a number sequence, and use RND(
+
1) for the numbers in the sequence. This should
give a close to theorhetically pure random number for statistical analysis and definitely gives a random
sequence for game play.
The RND of a minus number is not truly random at all. The parameter is passed as a seed to the random
number generation sequence. This technique can be used in debugging programs in a sense that a
predictable repeatable sequence can be obtained by RND minus tor program development. Suppose in a
game program you want to simulate rolling a six-headed die. Initially, you can see the random number
generator with the instruction
D~RND(-TI)
Subsequently, you can compute the value of the die with
D
=
INTI6'RND(1)
+
1)
PEEK, POKE:
PEEK is a function which allows the user to look at any location in the PET memory. The parameter
contains the memory address in decimal in the PET which to want to look at the result is a decimal
number between a and 255. BASIC is currently constructed so that the contents of any address greater
than hexadecimal COOO is automatically returned as zero. This is a legal constraint, posed by the
company who wrote the BASIC software to protect their copyright.
Example: To look at memory location 25, the expression is written:
?PEEK(25)
POKE
POKE is not a function but is written like a command. It allows the user to deposit a number into 110 or
read/write memory. The parameters are specified in a list after the command. The first parameter is the
memory address of where to put the information. It may range from a to 65536. The second parameter is
the actual value to be deposited. It must be between
a
and 255. For example, if we wanted to put the
character A at the first location of the screen memory we would write
POKE 32768,1
Some locations in memory cannot be changed (ROM) and others should not be changed (BASIC and
system variable RAM or I/O). If you POKE the latter, be prepared to reset your machine.
30

Advertisement

Table of Contents
loading

This manual is also suitable for:

Pet 2001-8

Table of Contents