A normal distribution is generated as seen below.
Image
It works by working out the amount of times heads is flipped when you flip the coin 10 times. It then repeats 10 flips 100K times.
The result is a normal distribution showing the distribution of values as a histogram.
Image1 Image2
Read README ...
Issue: Plotted graph using matplotlib isn't smooth I havent set a value for the bin values (x axis). (See above)
Image3
I've tried increasing the amount of trials. eg 100 Flips done 100K times but it still looks fixed like blocks not fluid like a normal distribution.
Image 4
I cant post images but if you check the github yashGaneshgudi it mathches the issue... Thanks https://github.com/yashGaneshgudi/Normal-Distribution
UPDATE ADDED CODE
import random
results=[]
for i in range (100000):
heads=0
print(i)
for i in range(10):
coin = random.randint(0, 1)
if coin == 1:
heads += 1
results.append(heads)
print(heads)
import matplotlib.pyplot as plt
plt.hist(results)
plt.show()
results
can only take integer values between 0 and 10. There is no way that it could produce a smooth histogram, since there are only eleven possible values for the data.
Try adding more coin flips, e.g.
import random
results=[]
for i in range (100000):
heads=0
print(i)
for i in range(1000):
coin = random.randint(0, 1)
if coin == 1:
heads += 1
results.append(heads)
print(heads)
import matplotlib.pyplot as plt
plt.hist(results, bins=50)
plt.show()
This will produce a smoother plot, but there will be periodic spikes. Reason why is left as an exercise. (Hint: think about where the bin lines are placed)