function draw_color = urn_sample ( marble_num, draw_num, color_num, color_count )

%*****************************************************************************80
%
%% URN_SAMPLE simulates the sampling of an urn of colored marbles.
%
%  Discussion:
%
%    An urn contains a number of marbles of various colors.  
%
%    A random sample of marbles is drawn, and the colors are reported.
%
%  Licensing:
%
%    This code is distributed under the GNU LGPL license.
%
%  Modified:
%
%    23 January 2019
%
%  Author:
%
%    John Burkardt
%
%  Parameters:
%
%    Input, integer MARBLE_NUM, the number of marbles.
%
%    Input, integer DRAW_NUM, the number of marbles to draw.
%
%    Input, integer COLOR_NUM, the number of colors.
%
%    Input, integer COLOR_COUNT(COLOR_NUM), 
%
%    Output, integer DRAW_COLOR(COLOR_NUM), the number of marbles drawn,
%    of each color.
%

%
%  Randomly sample DRAW_NUM distinct integers from 1:MARBLE_NUM.
%
  y = randsample ( marble_num, draw_num );
%
%  Ascending sort Y.
%
  y = sort ( y );
%
%  Assume the balls are colored in order.
%  Count the balls of each color by counting integers between limits.
%
  t = 0;
  for i = 1 : color_num
    b = t;
    t = t + color_count(i);
    draw_color(i) = sum ( b < y & y <= t );
  end

  return
end
