function T = coinflips(n, p, N)

% Coin flip simulation.
% n is the number of coin flips per trial.
% p is the coin's probability of heads.
% N is the number of trials.
% T is n x N, with the results of each trial in the columns.

T = zeros(n,N);  % Initialize TRIALS matrix

for i = 1:N
    t = [ ];  % Initialize trial vector
    for j = 1:n
       if rand < p
            t = [t; 1];  % Add head to trial
       else
            t = [t; 0];  % Add tail to trial
       end
    end
    T(:, i) = t;  % Update TRIALS matrix 
                      % Each trial t is a column
end 