function prob = long ( )

%*****************************************************************************80
%
%% long() analyzes a stick breaking problem.
%
%  Discussion:
%
%    A stick of unit length is randomly broken into two pieces.
%
%    Then the longer of the two pieces is randomly broken again.
%
%    What is the probability that these three pieces form a triangle?
%
%  Licensing:
%
%    This code is distributed under the MIT license. 
%
%  Modified:
%
%    08 May 2019
%
%  Author:
%
%    Paul Nahin
%
%  Reference:
%
%    Paul Nahin,
%    Will You Be Alive 10 Years From Now?,
%    Princeton, 2014,
%    ISBN: 978-0691156804,
%    LC: QA273.25.N344
%
%  Output:
%
%    real prob, the probability that a triangle is formed.
%
  total = 0;

  trial_num = 100000;

  for loop = 1 : trial_num

    x = rand ( );
    y = 1.0 - x;
    big = max ( x, y );
    s = min ( x, y );

    v = big * rand ( );
    u = big - v;

    m = min ( u, v );
    l = max ( u, v );
%
%  Check triangle inequality.
%
    if ( l < s + m && m < s + l && s < m + l )
      total = total + 1;
    end

  end

  prob = total / trial_num;

  return
end
