[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Apple II Random Events?
Gabriel Morales writes ...
>
> I was wondering:
>
> How does an Apple II, say using the BASIC RND command, determine a
> random number?
>
Here is a bit of additional info ...
When you do something like Z= RND(1) in Applesoft BASIC, Z normally
acquires a 9-digit decimal value ranging from 0 to just below 1. For
example, Z may end up as 0.357200114 . To obtain an integer you just
multiply and INT the result ...
10 X= INT (RND(1) * 100)
The above line gives X an integer value ranging from 0 through 99.
One problem in many games is finding a way to avoid having the
startup situation always be the same or be easily predictable-- like
you may not want the player's party to exit the Adventurer's Inn and
always run into a gang of Orcs.
For example, if MT is monster type and
250 MT= INT (RND(1) * 16)
is the first time since power-up that an RND(1) is done, then, on our
II+, you will always run into a gang of type 4 monsters at the start of
the game.
A pretty good way to mix things up is to place code which calls the
RND() function inside some subroutine which gets frequently accessed and
where the the number of RND() calls is not predictable. For instance,
you could place ZZ= RND(1) inside a Get Key routine ...
50 REM GET A KEY (RETURNS ASCII CODE IN AC)
60 ZZ= RND(1): ZZ= PEEK(49152): IF ZZ<128 THEN 60
70 AC= ZZ-128: ZZ= PEEK(49168): RETURN
In the above, the number of times ZZ= RND(1) is executed depends
upon how long the player takes to press a key, say, to answer Yes or No
to some question. Thousands of RND(1) values may be generated each time
the player is deciding something and, so, the results of other RND(1)
uses later in the game become unpredictable.
Rubywand