The Normal (or Gaussian) distribution is a frequently used distribution in statistics. While most programming languages provide a uniformly distributed random number generator, one can derive normally distributed random numbers from a uniform generator.



The task

 Take a uniform random number generator and create a large (you decide how large) set of numbers that follow a normal (Gaussian) distribution. Calculate the dataset's mean and standard deviation, and show a histogram of the data.
 Mention any native language support for the generation of normally distributed random numbers.


Reference

 You may refer to code in Statistics/Basic if available.


 
s	= 100000
h$	= "============================================================="
h$	= h$ + h$
dim ndis(s)
' mean and standard deviation.
mx	= -9999
mn	=  9999
sum	= 0
sumSqr	= 0
for i = 1 to s	' find minimum and maximum
	ms	= rnd(1)
	ss	= rnd(1)
	nd 	= (-2 * log(ms))^0.5 * cos(2 *3.14159265 * ss) ' normal distribution
	ndis(i)	= nd
	mx	= max(mx, nd)
	mn	= min(mn, nd)
	sum	= sum + nd
	sumSqr	= sumSqr + nd ^ 2
next i
 
mean	= sum / s
range	= mx - mn
 
print "Samples   :"; s
print "Largest   :"; mx
print "Smallest  :"; mn
print "Range     :"; range
print "Mean      :"; mean
print "Stand Dev :"; (sumSqr /s -mean^2)^0.5
 
'Show chart of histogram
nBins	= 50
dim bins(nBins)
for i = 1 to s
	z	= int((ndis(i) -mn) /range *nBins)
	bins(z)	= bins(z) + 1 
	mb	= max(bins(z),mb)
next i
for b = 0 to nBins -1
 print using("##",b);" ";using("#####",bins(b));" ";left$(h$,(bins(b) / mb) * 90)
next b
END