Contents / Part 2 / Previous chapter / Next chapter / Index
The BBC computer contains an 'elapsed time' clock. That means that the clock ticks away at a hundred ticks per second but it does not know the real time. However, you can set it and read it. Once set it will stay running until you turn the power off or you do a 'hard reset' (see page 142). It can be set to any value, for example 0,
TIME = 0
This program will print a running stopwatch in the middle of the screen:
5 CLS
10 T = TIME
20 PRINT TAB(10,12);(TIME-7)/100;
30 GOTO 20
There is a program to print a 24 hour clock on page 131.
When writing games (and simulations), we very often want the computer to make a random choice - or to pick a random number. The most useful function for this is RND(X) which picks a random number between 1 and X. The program below prints out a new random number between 1 and 6 every time a key is pressed: rather like throwing a dice.
10 PRINT RND(6)
20 G=GET
30 GOTO 10
and this program draws random triangles in random colours
10 MODES
20 PLOT 85,RND(1200),RND(1000)
30 GCOL 0,RND(3)
40 GOTO 20
Sometimes it is useful to be able to re-set the random number generator to a known value. That may sound a bit strange but when testing a program it is sometimes convenient to have a predictable set of "random numbers"! To do this the number in brackets after the RND must be a negative number. Thus X=RND(-8) will ensure that the number sequence resulting from RND(6) is repeatable.