Probability patterns

Random is typically seen as the opposite of pattern. As Ian Stewart wrote:

“Mathematics is about patterns. The random workings of chance seem to be about as far from patterns as you can get. In fact, one of the current definitions of ‘random’ boils down to ‘lacking any discernible pattern’. Mathematicians had been in investigating patterns in geometry, algebra and analysis for centuries before they realized that even randomness has its own patterns. But the patterns of chance do not conflict with the idea that random events have no pattern, because the regularities of random events are statistical.  They are features of a whole series of events, such as the average behavior over a long run of trials.” (Stewart 2012, page 109)

Look at the frequencies of results from random chance. You’ll see distinct patterns appear. 

As an introductory example, we will show you how to code a coin flip and graph the results. Here are 1000 randomly tossed coins on a table, greens are heads, reds are tails. The number of heads should be relatively close to 500, but of course will vary. We toss the coins and count repeatedly, and plot the results. Below are the results after ten trials, and then the results after 10,000 trials. A bell curve appears. 

Here’s the model in Scratch, using just a few lines of code. Our scratch model has balls bounce off of pegs with a 50/50 probability of going left or right. The result is the same binomial probability distribution. We made the model with real beads and Lego, with the same results (our 30 sec video)

The simple models shows how an almost bell-shaped curve results from the coin tosses. This is a “binomial distribution.”  A wide variety of fields use binomial and normal distributions to estimate the likelihood of events. 

We also do this in Python, using exactly the same ideas. You certainly don’t need to try this in Python, but if you want to, we give you full instructions.  Here is the essence of the code. The main idea is to simulate the coin toss using a random function:  

import random

[sum([random.randint(0,1) for i in range(1000)]) for j in range(10)]


Then we visualize, as we did above in NetLogo, using a histogram:

import random

from pylab import *

n = 1000    # number of coin tosses in each trial

t = 1000    # number of trials

trials = [sum([random.randint(0,1) for i in range(n)]) for j in range(t)]

freq = [trials.count(k) for k in range(n+1)]  

bar(range(n+1), freq, align=’center’)



The below model, which comes with NetLogo, shows you more about how this coin tossing experiment results in a bell-shaped curve, a binomial distribution corresponding in shape to the normal curve.  Balls fall from the top, bounce off the yellow pegs and stack up at the bottom of the triangle, showing the same bell-shaped curve. 


Stewart, Ian. In Pursuit of the Unknown: 17 Equations that Changed the World. New York: Basic Books. 2012.