function p = triangle_sample_reflect ( t, n )

%*****************************************************************************80
%
%% triangle_sample_reflect() returns random points in a triangle.
%
%  Discussion:
%
%    The "reflection" method is used, which is particularly easy to
%    understand and implement.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    11 January 2025
%
%  Author:
%
%    John Burkardt
%
%  Input:
%
%    real t(3,2): the triangle vertices.
%
%    integer n: the number of points to generate.
%
%  Output:
%
%    real p(n,2): random points in the triangle.
%
  u = rand ( n, 1 );
  v = rand ( n, 1 );
%
%  If 1.0 < u + v, these points are in the parallelogram, but not the triangle.
%  Reflect them.
%
  i = find ( 1.0 < u + v );
  u(i) = 1.0 - u(i);
  v(i) = 1.0 - v(i);

  p = ( 1.0 - u - v ) * t(1,1:2) + u * t(2,1:2) + v * t(3,1:2);

  return
end
