% clt_test.m
% example solution of problem 1, exercise 4

% sample 1 million random numbers

pop_size=100000;
r=rand(1,pop_size);
exp_parameter=0.5;

exp_r=expinv(r,exp_parameter);

% loop through and sample 1000 times
n_runs=1000;
sample_size=100;
sample_mean=zeros(1,n_runs);
sample_mean_exp=zeros(1,n_runs);

for x=1:n_runs,
   c=randperm(pop_size);
   sample_mean(x)=mean(r(c(1:sample_size)));
   sample_mean_exp(x)=mean(exp_r(c(1:sample_size)));
end;

% plot histogram

figure(1)
clf
subplot(1,2,1)
hist(r,50);
subplot(1,2,2)
hist(sample_mean,50);

figure(2)
clf
subplot(1,2,1)
hist(exp_r,50);
subplot(1,2,2)
hist(sample_mean_exp,50);
