
A = zeros(100,1);
for n_tries = 1:100,
    numberExperiments = 1000;
    for count = 1:numberExperiments,
    %   Generate a randomn number k with value 1, 2, 3, 4, 5, or 6, with
    %   probability 1/6.  
        r = rand;
        if (r < 1.0/6)
         k = 1;
        elseif (r < 2.0/6)
         k = 2;
        elseif (r < 3.0/6)
         k = 3;
        elseif (r < 4.0/6)
         k = 4;
        elseif (r < 5.0/6)
         k = 5;
        else
         k = 6;
        end
        A(n_tries) = A(n_tries) + k;        % Add each value of k
    end
    A(n_tries) = A(n_tries)/numberExperiments; % Divide by 1000 to get the average of k 
end

hist(A)                                     % Plot histogram of average values


