## Micropower |
## Volume 1 · Number 3 · November 1981 |

Page 7 of 33 |
---|

with the RND function is negative, a new sequence of numbers will be started. While different negative numbers produce different sequences, any particular negative number will always produce the the same sequence. If the argument is greater than zero, the function returns the next number in the current sequence, while RND(0) reproduces the previous number output in the current series.

To vary the start of a game you need a random start somewhere in the list, so to speak, of the numbers being generated. One method would be as follows:

10 INPUT"Enter a no.";N:IF N > 0 THEN N= -N 20 A = RND(N)

When the player enters a number he selects a new sequence for the game. However, this allows players to cheat – they can affect the random sequence, and hence the course of the game, by there initial selection. A better method is to use the keyboard scan user routine referred to above (see the manual for the m/c code and the decimal equivalents):

10 DOKE 4100, 3200:REM Tell BASIC where routine is located 20 PRINT "When you are ready, press any key" 30 A=RND(1):B=USR(0):IF B=0 THEN 30

Here, each time you start, the generation of numbers will stop at a different point due to the varying time taken to react to the message.

Another helpful routine which uses the RND function is the generation of integers within a given range e.g. a number between 1 and 12. Some BASICS already have this as a built-in function. On the Nascom you need to adopt a formula similar to the following:

10 A=INT((RND(1)*T)+B)

where T equals the top of the range and B equals the bottom. If we substitute 12 and 1 for T and B we get 12 x (no. between 0 and 0.999999) which should be less than 12. If we then add 1 and then reduce the answer to integer format the result in most cases will be in range 1 to 12. However, due to the rounding system in the BASIC a number larger than 0.999995 is treated as being equal to 1, and the computer will then, in this instance produce answers in the range 2 to 13. So for a perfect program you will need to test for data which is out of range.

Next issue will probably see the last look at various statements and functions within BASIC. After that we can perhaps dissect a few programs or interesting parts of programs, and in doing so cover various points not looked at so far.

Happy Keyboard Bashing !!

Page 7 of 33 |
---|