% Filename: DiceRolling
% M-file to compute probability of rolling doubles or a sum of 6.
% Number of times to run experiment
N = 1000;
% Initialize sum of probabilities
C = 0;
for i = 1:N
% Set event counter to zero
c = 0;
for j = 1:N
% Roll two dice x and y
x = ceil(6*rand(1));
y = ceil(6*rand(1));
% If roll doubles or sum of 6, increase counter.
% Otherwise do nothing.
if (x==y || (x+y)==6)
c = c + 1;
end
end
% Add on prob of event after rolling N times
C = C + c/N;
end
% Print out result
fprintf('P(doubles OR sum of 6) = %6.4f\n',C/N);