**Part 1 of several...The Mysterious And Unpredictable RND**

Bob Albrecht and George Firedrake

*From a book of the same name by Dymax Publishing Co., copyright © 1980 Dymax. Permission to reprint by teachers for classroom use is granted.*

**Preface**

Bob Albrecht and his friend, George Firedrake, have joined together to bring you this *teach yourself* guide to the PET's world of random numbers and the RaNDom (RND) function. In this self contained description of how the function works, they lead you step-by-step through examples and exercises that help you learn the full capabilities of RND.

Using small programming examples, Bob and George explore with you a series of seemingly simple applications. Don't let the apparent simplicity fool you! The material that is covered deals with probabilities, sampling, general mathematics, proportions, and fantasy gaming.

For the classroom teacher, the booklet is a rich resource on how to present concepts using random numbers - *with or without* a computer. Bob and George, long time teachers of kids, show you how to imaginatively and creatively lead a person to an understanding of randomness without getting entrapped in jargon and complexity.

For the newcomer to programming, or anyone who knows how to program but doesn't have a lot of experience with the RND function, there are exercises and experiments to try. Of course the answers to the exercises are given in the back of the booklet, but Bob and George encourage you to work out your own solutions. There is an old and ancient dragon-song that George sings that tells you why he believes this to be best. A line from the song goes like this, "Work done by the Self is a lasting Work, and will last beyond all Time."

What does this booklet have to do with dragons? Well, that is quite a story, and only a small part can be told here. Bob Albrecht *is* known throughout the world, by both children and adults, as the Dragon. He is fond of dragon-things, and there are people who believe that he may indeed be a real dragon disguised for a while as a human, so that we will listen to what he has to say about kids and learning. Dragons are wise creatures but rather imposing when encountered on a one-to-one basis.

George Firedrake and Bob are old friends. They are said to have met and adventured together several thousand years ago. The chronicle of their escapades, according to George, forms the core of an elaborate dragonsong that takes at least 1000 nights to sing.

Recently awakening from a long sleep, George recalled a dream that he had experienced. In the dream, he had been given a vision of an important task to be done. He was to find Bob, renew their friendship, and begin an adventure that involved the children of the planet Earth. He and Bob were to help the children to acquire knowledge and mastery of the planet's new technologies.

When George found Bob, Bob was already at work on the task. Bob had dreamed the same dream.

All of this diversion probably still doesn't tell you what this booklet has to do with dragons. That's true. Dragons are often reluctant to divulge their larger plans. They like to let events unfold slowly. A few hundred years to a dragon is hardly any time at all.

The only clue Bob and George would give is that everyone should spend some time with the fantasy gaming and fantasy adventure portions of the booklet. They said that *many* kids already know about fantasy gaming, and that the ability to play fantasy games and experience fantasy adventures was important to what the dragons were here for this time. In fact, George confided that the fantasy gaming material presented in this booklet is just part of an entire series that the two dragons have in preparation.

As always, even a dragon's musings about randomness and random numbers is anything but random.

*Ramon Zamora*

**Random Numbers**

Random numbers? A random number is a number chosen at random from a given set of numbers. Many board games include dice or a spinner for generating random numbers.

- Roll the dice - they come up 7. Move 7 spaces.
- Want a random number from 0 to 9? Spin the spinner. We show it stopped at 3.

Have you played fantasy adventure games such as *Runequest* or *Dungeons and Dragons* or *Tunnels and Trolls?* These games use special dice to roll random numbers.

PET BASIC has a special function, called the RND function, which makes it easy to compute numbers that seem to be chosen at random. Let's try some, using the following program.

100 REM***RANDOM NUMBER SAMPLER 110 PRINT "[CLR]"; 120 INPUT "HOW MANY RANDOM NUMBERS" ; N 130 PRINT 200 REM***PRINT N RANDOM NUMBERS 210 FOR K = 1 TO N 220 PRINT RND(1), 230 NEXT K 240 PRINT 999 END

We ran the program and asked for 10 random numbers. Here is what happened.

HOW MANY RANDOM NUMBERS? 10 .423845266 .224490519 .0841791929 .0109476861 .815469086 .0103099732 .177593567 .0611899468 .70222491 .549286173 READY |

We got a sample of 10 random numbers. Let's get another sample of 10 random numbers. Again, we type RUN and press RETURN.

HOW MANY RANDOM NUMBERS? 10 .510481989 .984101932 .927432526 .234026046 .936769068 .966004475 .577093285 .734453062 .0876111783 .614376942 READY |

Aha! This bunch of numbers is different from the first bunch. Well, we told you that these are random numbers. In fact, if you put our program into your PET you will probably get yet another bunch of random numbers. That's the idea of random numbers. They are, well, random!

The statement:

220 PRINT RND(1), tells the PET to compute and print one random number. We use the number 1 in parentheses following RND. However, any positive number is oK.RND ( )Put any positive number here.

EXPERIMENT! What happens if you put zero or a negative number in parentheses. Try it and find out.

From now on, we will call the numbers computed by the RND function RND numbers. We will suggest experiments for you to try to find out things about RND numbers and use RND numbers in programs to simulate, or imitate, events such as flipping coins or rolling dice.

**How Big? How Small?**

Look at the RND numbers in our two samples.

**Exercise 1.**

(a) What is the smallest RND number?

____________

(b) What is the largest RND number?

____________

Hmmm... how could we find the smallest or largest RND number in a large sample? For example, suppose we want to know the largest number in a sample of 1000 RND numbers? Sounds like a lot of work! Well, that is just the kind of work that the PET loves to do.

Here is a program to generate a bunch of RND numbers and print only the largest number.

100 REM***LARGEST RND NUMBER IN A SAMPLE 200 REM***FIND OUT HOW BIG A SAMPLE 210 PRINT, "[CLR]"; 220 PRINT 230 INPUT "HOW MANY RND NUMBERS" ; N 300 REM***SET BIG EQUAL TO FIRST RND NUMBER 310 BIG = RND (1) 400 REM***DO REST OF SAMPLE. COMPARE EACH RND 410 REM***NUMBER WITH BIG. IF BIGGER, REPLACE. 420 FOR K = 1 TO N-1 430 X = RND (1) 440 IF X < BIG THEN BIG = X 450 NEXT K 500 REM***PRINT BIG AND GO BACK FOR MORE 510 PRINT "LARGEST NUMBER IN SAMPLE IS" BIG 520 GOTO 220 999 END

We tried it. Here is what happened.

HOW MANY RND NUMBERS? 10 LARGEST NUMBER IN SAMPLE IS .921818131 HOW MANY RND NUMBERS? 10 LARGEST NUMBER IN SAMPLE IS .674903427 HOW MANY RND NUMBERS? 100 LARGEST NUMBER IN SAMPLE IS .996202748 HOW MANY RND NUMBERS? 1000 LARGEST NUMBER IN SAMPLE IS .997077099 HOW MANY RND NUMBERS? 10000 LARGEST NUMBER IN SAMPLE IS .999999136 HOW MANY RND NUMBERS?

Anyone want to try for 100000?

Well, there seems to be some evidence (not proof) that RND numbers are always less than 1. Do notice, though, that with a big sample such as 10000, the largest RND number sort of creeps up on 1.

Yes, .999999136 is close to 1.

**Exercise 2. Smallest RND number in a sample.**

Your turn. Write a program to find and print the smallest RND number in a sample. We suggest you do it by modifying our program to find the largest RND number in a sample. Use SMALL instead of BIG. Later, SMALL and BIG will get together in the same program. In the meantime....

When we ran our program to find the smallest number in a sample, here is what happened.

HOW MANY RND NUMBERS? 10 SMALLEST NUMBER IN SAMPLE IS .152609562 HOW MANY RND NUMBERS? 10 SMALLEST NUMBER IN SAMPLE IS .0962136245 HOW MANY RND NUMBERS? 100 SMALLEST NUMBER IN SAMPLE IS 0.132498463 HOW MANY RND NUMBERS? 100 SMALLEST NUMBER IN SAMPLE IS 5.48253455E-03 HOW MANY RND NUMBERS? 1000 SMALLEST NUMBER IN SAMPLE IS 1.17754321E-03 HOW MANY RND NUMBERS? 10000 SMALLEST NUMBER IN SAMPLE IS 7.84862186E-06 HOW MANY RND NUMBERS?

and so on. Take over!

The smallest number can be very small. But, according to the above evidence, it is never zero. Beware! Evidence is not proof.

However, if you run lots of big samples and the smallest number is usually close to zero (but never zero) and the largest number is usually close to one (but never one), you begin to feel secure in making a conjecture, such as the following.

**Conjecture 1.** RND numbers are greater than zero and less than one. Or to put it into more math-like jargon,

0 < RNDA(1) < 1

which says "RND(1) is greater than zero and less than one."

And all this stuff leads into our next program, something for you to do.

**Exercise 3.. The small and the big.**

Write a program to find and print both the smallest number and the largest number in a sample of RND numbers.

A RUN might look like this.

HOW MANY RND NUMBERS? 10 SMALLEST NUMBER IN SAMPLE IS .010309732 LARGEST NUMBER IN SAMPLE IS .849286173 HOW MANY RND NUMBERS? 100 SMALLEST NUMBER IN SAMPLE IS .0153301686 LARGEST NUMBER IN SAMPLE IS .984101932 HOW MANY RND NUMBERS? 1000 SMALLEST NUMBER IN SAMPLE IS 4.23408483E-04 LARGEST NUMBER IN SAMPLE IS .995799597 HOW MANY RND NUMBERS?