function p = ratio2 ( k )

%*****************************************************************************80
%
%% ratio2() tabulates how often a random ratio exceeds 1, 2, 3, ...
%
%  Discussion:
%
%    We pick three random numbers from [0,1] uniformly.  
%    What is the probability that the ratio of the largest to the smallest
%    value is more than k?
%
%  Licensing:
%
%    This code is distributed under the MIT license. 
%
%  Modified:
%
%    07 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
%
%  Input:
%
%    real k, the ratio limit.
%
%  Output:
%
%    real p, the probability.
%
  trial_num = 100000;

  total = 0;
  for trials = 1 : trial_num
    x = rand ( 3, 1 );
    r = max ( x ) / min ( x );
    if ( k <= r )
      total = total + 1;
    end
  end

  p = total / trial_num;

  return
end
