## Exploring Computing Animation, Simulation & Modeling

4.1 Unit Overview

4.2 Android Mash Tutorial

4.3 Android Mash Projects

4.4 Logo Part 1

4.5 Coin Flip Simulation Tutorial

4.6 Coin Flip Experiment

4.7 Pseudo Random Numbers

4.8 Coin Flip Simulation Projects

4.9 Real World Models

4.10 Abstraction Inside the CPU

4.11BB Privacy

4.12 Wrap Up ## QR Code for Coin Flip App Coin Flip Experiment

## Coin Flip Experiment: In this lesson you will use a pre-built app, CoinFlipExperiment, to conduct an experiment aimed at determining how ‘good’ App Inventor is at generating random numbers.The app will let you ‘flip a coin’ N times and display the results. You should record and tally the results and calculate the average percentage of heads. The expectation is that as N gets large, the average should approach 50%.

Unit Objectives

• Use software to conduct an experiment.
• Make and test a hypothesis about App Inventor's ability to generate random numbers.

Here are some things you should know about how computers and computer languages (App Inventor) implement randomness:

• Randomness is used in lots of programs, especially games (Android Mash) and simulations (Coin Flip, 4-bit Computer Simulator).
• Creating a truly random process is hard to do. And creating a truly random process in a computer is no exception.
• Because creating true randomness is hard, computers use algorithms known as pseudo random number generators (PRNGs) to simulate randomness. This is much easier to do than generating truly random numbers. If you are curious about how PRNGs work, the next lesson goes into the details.
• PRNGs generate a sequence of "random seeming" numbers.
• PRNGs are models of true randomness. As such, they can be 'good' or 'bad' depending on how well they approximate true randomness. Much research by mathematicians and computer scientists goes into creating good PRNGs.
• App Inventor uses a standard and well established PRNG, which should do a good job of modeling randomness.

Our hypothesis for this experiment: App Inventor's PRNG provides a good model of randomness.

Perform the following steps.

1. Form a team of several students.
2. Repeatedly run the app on each device and record the number of heads and tails received in each trial. Do at least 20 runs (trials) among the team. The maximum number of "flips" per trial is 100. Your team should have at least 2000 "flips".
3. Tally your results and calculate the percentage of heads for each trial. In addition, calculate the cumulative number and percentage of heads after each trial. For example, after the 5th trial of 100 flips, your table will show the number and percentage of heads for 500 flips.
4. Record your teams results for each trial in a neatly organized table. That is, if you did 20 trials of 100 coin flips each, your table should have 20 rows of results, with the percentage for each trial along with the cumulative numbers.
5. Here is a Google spreadsheet sthat you can use to record your data. Just enter your data in columns B and C. The rest of the columns will be calculated automatically.
6. According to your results, does App Inventor's PRNG provide a good model of randomness?
7. A friend claims that flipping a coin 100 times and finding that it comes up heads only 45% of the time shows that the coin is biased. How should you reply?

8. To get started, open use the QR code in the left column to download the Coin Flip Experiment App.