% random.m
% An M-file that generates Gaussian data from uniformly
% distributed data, thus demonstrating the Central Limit Theorem
% calls m-files:  pdfdat.m, datstats.m,          

  clear

  s1='This m-file uses the Central Limit Theorem to generate Gaussian random';
  s2=' data from uniformly distributed random data';
  s3='             ';
% s2=[s s1]
  disp(s1)
  disp(s2)
  disp(s3)  

% create a random population of means of size nn:

  dataname = 'random';

  nm=input('What is the number of means in the distribution? (nm = 100-5000) ');
  nn=input('What is the size of each sample? (nn = 1-300) ');
  %sd=input('Enter a seed value for the random generator ');
  %rand('seed',sd)
  rand('state',sum(100*clock));   % Appropriate for V5.0 and higher
  muX=zeros(1,nm);
  for i = 1:nm
    Xdat=rand(nn,1);
    muX(i)=mean(Xdat);
  end;
  data=muX';
       
% calculate the probability density function
  pdfdat
  datstats

  name = input('Type your name so it can be printed on the plot. ','s');
  string = ['number of means = ' num2str(nm) ', mean sample size = '  num2str(nn)];

  pltpdfdat
  

