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


 
PROGRAM DISTRIBUTION
 
!
! for rosettacode.org
!
 
! formulas taken from TI-59 Master Library manual
 
CONST NUM_ITEM=1000
 
!VAR SUMX#,SUMX2#,R1#,R2#,Z#,I%
 
DIM A#[1000]
 
BEGIN
! seeds random number generator with system time
   RANDOMIZE(TIMER)
 
   PRINT(CHR$(12);)  !CLS
   SUMX#=0  SUMX2#=0
 
   FOR I%=1 TO NUM_ITEM DO
      R1#=RND(1)  R2#=RND(1)
      Z#=SQR(-2*LOG(R1#))*COS(2*π*R2#)
      A#[I%]=Z#/2+1   ! I want a normal distribution with
                      !      mean=1 and std.dev=0.5
      SUMX#+=A#[I%]  SUMX2#+=A#[I%]*A#[I%]
   END FOR
 
   Z#=SUMX#/NUM_ITEM
 
   PRINT("Average is";Z#)
   PRINT("Standard dev. is";SQR(SUMX2#/NUM_ITEM-Z#*Z#))
 
END PROGRAM
 