function p = ratio1 ( k )

%*****************************************************************************80
%
%% ratio1() tabulates how often a random ratio exceeds 1, 2, 3, ...
%
%  Discussion:
%
%    We pick two random numbers from [0,1] uniformly.  
%    What is the probability that the ratio of the larger to the smaller
%    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, which should be about 1/k.
%
  trial_num = 100000;

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

  p = total / trial_num;

  return
end
