function [ xy, seed ] = quad_convex_random ( seed )

%*****************************************************************************80
%
%% QUAD_CONVEX_RANDOM returns a random convex quadrilateral.
%
%  Description:
%
%    The quadrilateral is constrained in that the vertices must all lie
%    with the unit square.
%
%  Licensing:
%
%    This code is distributed under the GNU LGPL license.
%
%  Modified:
%
%    25 January 2019
%
%  Author:
%
%    John Burkardt
%
%  Parameters:
%
%    Input, integer SEED, a seed for the random number generator.
%
%    Output, real XY(2,4), the coordinates of the
%    nodes of the quadrilateral, given in counterclockwise order.
%
%    Output, integer SEED, a seed for the random number generator.
%
  while ( true )
%
%  Generate a random quadrilateral.
%
    [ xy_random, seed ] = quad_random ( seed );
%
%  Break if the quadrilateral is convex.
%
    if ( quad_is_convex ( xy_random ) )
      break
    end

  end
%
%  Determine the convex hull.
%
  [ hull_num, hull ] = points_hull_2d ( 4, xy_random );
%
%  Make an ordered copy of the random points.
%
  for j = 1 : 4
    xy(1:2,j) = xy_random(1:2,hull(j));
  end

  return
end
