Task

Generate a collection filled with   1000   normally distributed random (or pseudo-random) numbers
with a mean of   1.0   and a   standard deviation   of   0.5



Many libraries only generate uniformly distributed random numbers. If so, you may use one of these algorithms.



Related task

   Standard deviation


window 1
 
local fn RandomZeroToOne as double
  double result
  cln result = (double)( (rand() % 100000 ) * 0.00001 );
end fn = result
 
local fn RandomGaussian as double
  double r = fn RandomZeroToOne
end fn = 1 + .5 * ( sqr( -2 * log(r) ) * cos( 2 * pi * r ) )
 
long i
double mean, std, a(1000)
 
for i = 1 to 1000
  a(i) = fn RandomGaussian
  mean += a(i)
next
mean = mean / 1000
 
for i = 1 to 1000
  std += ( a(i) - mean )^2
next
std = std / 1000
 
print "           Average:  "; mean
print "Standard Deviation:  "; std
 
HandleEvents