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%.
- 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.
- Form a team of several students.
- 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".
- 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.
- 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.
- 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.
- According to your results, does App Inventor's PRNG provide a good model of randomness?
- 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?
To get started, open use the QR code in the left column to download the Coin Flip Experiment App.
Make sure that you update your Google Site Portfolio