function s = square_opposite ( )

%*****************************************************************************80
%
%% square_opposite(): expected length of line between random points on opposite square sides.
%
%  Discussion:
%
%    We consider a unit square, and randomly choose a points on two
%    opposite sides and measure their distance.
%
%    The correct expected value is 1.0766.
%
%  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 s, an estimate for the expected length.
%    
  trial_num = 100000;

  total = 0;
  for trials = 1 : trial_num
    x1 = 0.0;
    y1 = rand ( );
    x2 = 1.0;
    y2 = rand ( );
    r = sqrt ( ( x1 - x2 )^2 + ( y1 - y2 )^2 );
    total = total + r;
  end

  s = total / trial_num;

  return
end
