function [ p, seed ] = triangle_reference_sample ( n, seed )

%*****************************************************************************80
%
%% TRIANGLE_REFERENCE_SAMPLE returns random points in the reference triangle.
%
%  Licensing:
%
%    This code is distributed under the GNU LGPL license.
%
%  Modified:
%
%    09 November 2015
%
%  Author:
%
%    John Burkardt
%
%  Parameters:
%
%    Input, integer N, the number of points to generate.
%
%    Input, integer SEED, a seed for the random number generator.
%
%    Output, real P(2,N), random points in the triangle.
%
%    Output, integer SEED, a seed for the random number generator.
%
  [ alpha, seed ] = r8vec_uniform_01 ( n, seed );
%
%  Interpret R as a percentage of the triangle's area.
%
%  Imagine a line L, parallel to side 1, so that the area between
%  vertex 1 and line L is R percent of the full triangle's area.
%
%  The line L will intersect sides 2 and 3 at a fraction
%  ALPHA = SQRT ( R ) of the distance from vertex 1 to vertices 2 and 3.
%
  alpha(1:n) = sqrt ( alpha(1:n) );

  [ beta, seed ] = r8vec_uniform_01 ( n, seed );

  p = zeros ( 2, n );

  p(1,1:n) = ( 1.0 - beta(1:n) ) .* alpha(1:n);
  p(2,1:n) =         beta(1:n)   .* alpha(1:n);

  return
end
