% TriStick
% Estimates the probability that a triangle can be formed
% from three sticks, each with random length between 0 and 1.
% When that happens, we say that you have "won" a game of
% "TriStick".

clc
% Initialize the running sum and the number of trials...
wins = 0;
N = 1000000;
for n=1:N
   % Play the nth game of TriStick
   % by picking the three sticks...
   a = rand(); b = rand(); c = rand();
   
   if (a<b+c) && (b<a+c) && (c<a+b)
      % No stick is longer than the
      % sum of the other two.
      wins = wins +1;
   end
end
% Estimate the prob of winning
p = wins/N;
fprintf('\n\nProb = %10.6f (based on %1d trials).\n',p,N)


    