NCSI Talks

   

Pseudo Random Numbers Learning Scenario


Shodor > NCSI Talks > Excel > Pseudo Random Numbers Learning Scenario

Learning Scenario - Pseudo Random Numbers (Excel)

Basic Model

Description

Random numbers on computers are almost never "true" random numbers. That is, since the computer calculates its random numbers through a series of algorithms, even if it is hard to detect a pattern, the numbers are not genuinely random. This model allows for students to explore what is known as "pseudo random numbers" and the algorithms that run behind such calculations. Through a series of shifts, multipliers, and other calculations, random numbers are generated and used to estimate the area under a curve. The integral calculated in this model is the area of the unit circle, equal to pi. Many trials yield a more accurate result, as the Law of Large Numbers states, so the model takes into account increasing amounts of random numbers to calculate pi.

Background Information

Pseudo random numbers are the closest that a computer can come to outputting random numbers. If a series of computer generated "random numbers" were to be analyzed, a pattern would eventually remove showing its non-randomness. Since the algorithms are often far above any human's casual calculation, though, pseudo random numbers are often still taken as random. This model will describe the process behind calculating some random numbers and using those numbers to calculate pi.

Science/Math

The fundamental principle behind this model is HAVE = HAD + CHANGE. Each time the simulation is run, the following calculations occur:

  1. The seed is multiplied by the multiplier and added to the shift
  2. The resulting number is divided by 1024 and the remainder is recorded
  3. The remainder is divided by 1024 to produce a decimal
  4. The decimal is used in the equation of a circle to find the area of the first quarter of the unit circle
  5. Five different blocks of 200 quarter-area estimates are multiplied by four to find the whole area of the unit circle
  6. The five estimates are averaged to find a more accurate prediction for pi

The CHANGE in the model is directly related to the certain processes that computers go through to calculate random numbers. Each step is another formula that ensures a more "random" number.

Teaching Strategies

An effective way of introducing this model is to ask the students to think of ways in which random numbers may or may not be generated by computers and about the benefits of the Law of Large Numbers. Ask the following questions:

  1. What actually is a random number? Why can computers not generate true random numbers?
  2. How could you calculate random numbers with just your calculator? What would make your random numbers more accurate?
  3. If you were to investigate the most popular desert type in your school, how would asking more people affect your results? Explain.
  4. How would you carry out this study? What would be the best way to select people to answer your survey question?

It might be beneficial for the students to write down answers to these questions and return to them after using the model to compare their preconceptions and results.

Implementation

How to use the model

This relatively simple model consists of a few inputs that may be changed in order to affect the numbers throughout the random number calculation:

  1. The multiplier will change the initial number the seed is multiplied by
  2. The shift will adjust the amount the seed is moved after the multiplier
  3. The seed affects the number that the simulation starts with

These parameters may all be changed within excel by double clicking on the cell that holds the respective numbers. As soon as the numbers are changed, the simulation will recalculate its random numbers based on the new inputs. While other cells can be studied for their formulas, the numbers cannot be changed without breaking the model.

Learning Objectives

  1. Understand the idea of pseudo random numbers and the process behind calculating them
  2. Understand the Law of Large Numbers

Objective 1

Since computers cannot calculate truly random numbers, simple algorithms can be used to output closer-to-random numbers. The processes behind these simulations can result in random numbers that can be used to calculate pi. Students should study each of these processes and how the worksheet is able to calculate random numbers from the initial three values set by the user. Ask the following questions:

  1. Study the "New 'Seed'" Column, where the whole random numbers are calculated. Do these appear to be random? Do you notice any patterns?
  2. Change the multiplier to 1and the shift to 1. Are there any patterns now? How is this not beneficial in calculating random numbers?
  3. The estimation of pi is calculated through the pseudo random numbers generated in the model. How are the estimations affected by the change in multiplier and shift?
  4. Does changing the initial seed result in any patterns? Why do you think this would or would not be the case?
  5. Study the formulas behind each of the calculations up to the LC-RNG column. How are each of these formulas attempting to approach randomness with their equations? Explain.

Objective 2

Through this objective, students will learn how an increasing sample size yields more accurate predictions. They should study the calculations behind estimating area of a unit circle and see how the random numbers allows for an increasingly accurate value of pi. Ask the following questions:

  1. Why are the random numbers converted to decimals in the LC-RNG column? What is the domain of these numbers? What is the domain of the first quadrant of a unit circle?
  2. What is the purpose of the calculations in the "SQRT(1-x^2)" column? How are these further manipulated to estimate pi?
  3. What is the range of each block used to calculate pi? How do you explain the differences between the numbers? How close are they to the actual number of pi? (3.1415926535...)
  4. How close is the average of these numbers to the actual number of pi? Why would this number have a different accuracy level than the others?
  5. Change the multiplier, shift, and initial seed. Do these affect the accuracy of the estimation of pi at all? Explain.

Extensions:

  1. Hotbits Random Number Generator
  2. Understand a simple random sample and its necessity in statistics

Extension 1

While random numbers cannot be generated solely by computer algorithms, the Hotbits random number generator has found a way to integrate computers and truly random variables in order to produce better numbers that are actually random. Have students research this topic and see the benefits in using real random numbers. Ask the following questions:

  1. How does the Hotbits random number generator attempt to overcome the problems with randomness found in other computer programs?
  2. Is there still a place for computer-bias in this generator? Explain.

Extension 2

In statistics, random numbers are applied for many tasks, such as selecting a set of people to survey or study. A simple random sample allows for a more accurate representation of the population as a whole. Have students study this tactic and the methods used for simple random sampling. Ask the following questions:

  1. What are the advantages of having a simple random sample when surveying a group of people? Explain.
  2. How would a truly simple random sample be calculated?
  3. Connect the concept of a simple random sample to the Law of Large Numbers. In ideal situations, would a simple random sample tell the most about a population? What other methods would work?
  4. Are there other "random" ways to select members of a population?

Related Models

Projectile Motion

This model presents an application for integrals-essentially what was calculated when estimating pi-in a more practical situation. An object is launched from a specific height and a number of variables are graphed. These include the force acting on the body, the momentum, and the displacement. Students may be able to extend their knowledge of integrals and calculate the area under the graphs of several variables in order to find displacement or velocity. While Pseudo Random Numbers was focused solely on the unit circle, the Projectile Motion model applies integrals to a more realistic situation.

Two Algorithms for Monte Carlo Integrals

The Pseudo Random Numbers model included basic activities with integrals and random numbers. The Monte Carlo Integrals model allows students to extend their experience of calculating integrals with random numbers to a couple different methods. Monte Carlo Integrals are calculated by finding the average area under a curve based on random points. This model will include both a description of how a Monte Carlo Integral is calculated as well as a discussion on pseudo-random numbers and their effect on computer calculations.

Problematic Patterns in Random Noise

The Law of Large Numbers came into play with Pseudo Random Numbers when multiple data points allowed for a better approximation of pi. The Problematic Patterns in Random Noise model expands upon the Law of Large numbers and allows students to approximate a trend in a set of data points through regression. With a greater number of data points, the regression becomes more accurate and the coefficient of determination grows closer to 1.0. Pseudo Random Numbers focused on having a large number of random numbers, but this model will show applications for the Law of Large Numbers in relation to studying mathematical trends.