For many analyses, we are interested in calculating repeatable results. However, much of this analysis relies on some random numbers being used. In Python, you can set seed for the random number generator to achieve repeatable results with the random.seed() function.
In this example, we simulate rolling a pair of dice and look at the outcome. We would expect the average total of the two dice to be six, which is the half-way point between the faces.
The script we are using is as follows:
# using pylab statistics and histogram
import pylab
import random
# set random seed so we can reproduce results
random.seed(113)
samples = 1000
# declare our dataset store
dice = []
# generate and save the samples
for i in range(samples):
total = random.randint(1,6) + random.randint(1,6)
dice.append(total)
# compute some statistics on the dice throws
print("Throw...