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.
The simple models shows how a bell-shaped curve results from the coin tosses. This is a binomial distribution, closely approximating a normal distribution. A wide variety of fields use binomial and normal distributions to estimate the likelihood of events. Play with the model (click here). That is a model we created in NetLogo. We also do this in Scratch and 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:
[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:
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. This is just a preview of our module on statistics that comes with your subscription kit.
Stewart, Ian. In Pursuit of the Unknown: 17 Equations that Changed the World. New York: Basic Books. 2012.