so basically I'm trying to run an stochastic experiment. It's very simple. Basically I wanted to see if what the central limit theorem says holds.
So simply put the idea of the central limit theorem is, that if we sample infinite samples of the same size from our stochastic experiment, the means of those samples are normally distributed.
So consider a dice. That dice is a magic dice and if you throw it, you can only get a 1,3,4 or 6. So you can't get a 2 and a 5. The probabilities are as follows:
P[1] = 2/6
P[3] = 1/6
P[4] = 1/6
P[6] = 2/6
Now if we take a sample size of 4, i.e. we throw the dice 4 times, write down what we got, take the mean and do that for lets say 100'000 times, we should, when plotted as an histogram, see a normal distribution.
I implemented that like this using python:
""" Set up the probability space """
experiment = [1,1,3,4,6,6]
""" Experiment configuration """
n = 4
m = 100000
bins = 20
def throwDice():
result = []
for i in range(0,n):
k = randrange(0,6)
print(k)
result.append(experiment[k])
return result
def sampleMeans():
means = []
for i in range(0,m):
means.append(sum(throwDice())/4)
return means
def createHistrogram():
means = sampleMeans()
plt.hist(means, bins)
plt.show()
""" Run he experiment """
createHistrogram()
which got me this
it's not surprising, that we have "holes" in e.g. 2.75 and 4.75 since we are missing 2 and 5 i.e. there are less possible samples which have a mean of 2.75 and 4.75. Same argument can be done for the others.
Now while everything looks good, my question is actually about the random generator of python. Is it fine to do it like this? What kind of random number generator would be best suited for such a simple "numerical experiment"?