# -*- coding: utf-8 -*-
"""
Created on Wed Jul 11 06:30:57 2018
@author: Klaus Elk
"""
import numpy as np
samples = 100000000
print("Samples = ",samples)
print()
#Output from d2_calc with n as index - 0 inserted when no calculaion was done
my = [0,0,1.12839154467,1.69256290199,2.05867005648, 2.32606679846, 2.53443003885, 2.70421293596,
2.84725965343, 2.97003526765, 3.07752134982,0,0,0,0, 3.47187549621,0,0,0,0, 3.73506045183]
#Array for Variance buildup
var = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
for n in (2,3,4,5,6,7,8,9,10,15,20):
iterations = samples
sum = 0
i=0
while i < iterations:
a = np.random.randn(n)
range = max(a)-min(a)
var[n] += np.square(range-my[n])
i += 1
print(n, np.sqrt(var[n]/(iterations-1)))
#OUTPUT:
#Samples = 100000000
#2 0.852614232894
#3 0.888409638003
#4 0.879804344963
#5 0.864032974589
#6 0.847944270829
#7 0.833199047801
#8 0.819879421762
#9 0.807888740141
#10 0.797023402088
#15 0.756207713601
#20 0.728701436637