Acorn Computers BBC Micro Model B w/8271 — Acorn BBC Micro Model B w/8271 User Guide Manual PDF (EN)

73 13 TIME, RND TIME The BBC Microcomputer 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 chapter 25). 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-T)/100; 30 GOTO 20 There is a program to print a 24 hour clock in chapter 23. RND 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 – like throwing a dice. 10 PRINT RND(6) 20 G=GET 30 GOTO 10 and this program draws random triangles in random colours 10 MODE5 20 PLOT 85,RND(1200),RND(1000) 30 GCOL 0,RND(3) 40 GOTO 20 Sometimes it is useful to be able to reset 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 parenthesis after the RND must be a negative number.

Thus X=RND(-8) will ensure that the number sequence resulting from RND is repeatable.