function [ x, seed ] = uniform_on_triangle01 ( n, seed )

%*****************************************************************************80
%
%% UNIFORM_ON_TRIANGLE01 maps uniform points onto the unit triangle.
%
%  Discussion:
%
%    The unit triangle is defined by the three vertices (1,0), (0,1) and (0,0).
%
%  Licensing:
%
%    This code is distributed under the GNU LGPL license.
%
%  Modified:
%
%    07 May 2013
%
%  Author:
%
%    John Burkardt
%
%  Parameters:
%
%    Input, integer N, the number of points.
%
%    Input/output, integer SEED, a seed for the random
%    number generator.
%
%    Output, real X(2,N), the points.
%
  s = sqrt ( 2.0 );

  a =   1.0       / ( 2.0 + s );
  b = ( 1.0 + s ) / ( 2.0 + s );
  
  x = zeros ( 2, n );

  for j = 1 : n
%
%  R can be regarded as the distance of the point on the perimeter,
%  as measured from the origin, along the perimeter.
%
    [ r, seed ] = r8_uniform_01 ( seed );
    r = ( 2.0 + s ) * r;
%
%  Case 1: between (0,0) and (1,0).
%
    if ( r <= a )

      x(1,j) = 0.0;
      x(2,j) = r;
%
%  Case 2: between (1,0) and (0,1).
%
    elseif ( r <= b )

      x(1,j) = 1.0 - ( r - a ) * sqrt ( 2.0 ) / 2.0;
      x(2,j) = 0.0 + ( r - a ) * sqrt ( 2.0 ) / 2.0;
%
%  Case 3: between (0,1) and (0,0).
%
    else

      x(1,j) = 0.0;
      x(2,j) = 1.0 - ( r - b );

    end

  end

  return
end
