% ---- Coin flip --------
clear;
numOne = 0;
trials = 10000;
randomNum = zeros(1,trials);
relFreq = zeros(1,trials);

for n=1:trials
    randomNum(n) = rand(1);
    if randomNum(n) > 0.5
        randomNum(n) = 1;
    else
        randomNum(n) = 0;
    end
    numOne = numOne + randomNum(n);
    relFreq(n) = numOne/n;
end
n=1:trials;
figure(1); clf
plot(n,randomNum, '*')
hold on
plot(n,relFreq, '.k')
hold off
