<!-- PDF page 65 -->

Press **ENTER** each time you want to throw the dice. To use **% RND** instead, change line 40 to read:

```
40 PRINT %1+ RND 6;" ";
```

and to use **RND ()** you need to write line 40 as:

```
40 PRINT 1+ RND (6);" ";
```

Aren't the latter two more readable?

The **RANDOMIZE** statement, is used to make **RND** and **% RND** start off at a definite place in its sequence of numbers, as you can see with this program:

```
10 RANDOMIZE 1
20 FOR n=1 TO 5: PRINT % RND
   100,: NEXT n
30 PRINT: GO TO 10
```

After each execution of **RANDOMIZE 1**, the **% RND** sequence starts off again with **97** and if you use **RND** instead of **% RND 100**, you'll get **0.0022735596**. You can use other numbers between **1** and **65535** in the **RANDOMIZE** statement to start the **RND** sequence off at different places.

If you had a program with **RND, RND() or %RND** in it and it also had some mistakes that you had not found, then it would help to use **RANDOMIZE** like this so that the program behaved the same way each time you ran it.

**RANDOMIZE** on its own (and **RANDOMIZE 0** has the same effect) is different, because it really does randomise **RND**, **RND()** and **% RND** – you can see this in the next program:

```
10 RANDOMIZE
20 PRINT % RND 65535: GO TO 10
```

The sequence you get here is not very random, because **RANDOMIZE** uses the time since the computer was switched on. Since this has gone up by the same amount each time **RANDOMIZE** is executed, the next **% RND** does more or less the same. You would get better randomness by replacing **GO TO 10** by **GO TO 20**. Here is a program to toss coins and count the numbers of heads and tails.

```
10 heads,tails=0
20 coin=% RND 2
30 ON coin: heads+=1:tails+=1
40 PRINT heads;",";tails,
50 IF tails<>0 THEN PRINT
   heads/tails;
60 PRINT: GO TO 20
```

The ratio of heads to tails should become approximately **1** if you go on long enough, because in the long run you expect approximately equal numbers of heads and tails.

Note that **RANDOMIZE** can also be written in short as **RAND** and it will expand to **RANDOMIZE**!

