Random numbers
When you throw dice it is hard to guess, or predict, what numbers you will get. Unpredictable numbers like these are called random numbers. Below you can find out how to make a computer produce random numbers. The command is quite complicated, but it is useful in all sorts of programs.
PRINT INT(RND*10+1)
This produces a random number between 1 and 10.
Displaying random numbers
Here is a simple random number program to try. Line 40 tells the computer to pick a number between 1 and 20 and display it on the screen. Run the program a few times. The computer will pick a new number each time.
NEW 10 CLS 20 PRINT "HERE IS A NUMBER" 30 PRINT "BETWEEN 1 AND 20" 40 PRINT INT(RND*20+1) RUN
How does RND work?
To complete the instruction you need to multiply by the number of numbers the computer can choose from, and add the lowest number it can pick.
For example, to make the computer pick numbers from 1 to 6, like a dice, you need the instruction below.
PRINT INT(RND*6+1)
