function d = flies_simulation ( n )

%*****************************************************************************80
%
%% flies_simulation() estimates the average distance between two flies.
%
%  Discussion:
%
%    Two flies land at random points on a dish of radius 1.
%    On average, how far apart are the flies?
%
%  Licensing:
%
%    This code is distributed under the MIT license. 
%
%  Modified:
%
%    22 July 2022
%
%  Author:
%
%    John Burkardt
%
%  Input:
%
%    integer n: the number of times the experiment is carried out.
%
%  Output:
%
%    real d[n]: the observed distances.
%
  r1 = sqrt ( rand ( n, 1 ) );
  t1 = 2.0 * pi * rand ( n, 1 );

  r2 = sqrt ( rand ( n, 1 ) );
  t2 = 2.0 * pi * rand ( n, 1 );

  d = sqrt (  ( r1 .* cos ( t1 ) - r2 .* cos ( t2 ) ) .^ 2 ...
            + ( r1 .* sin ( t1 ) - r2 .* sin ( t2 ) ) .^ 2 );

  return
end

