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 MIT license.
%
%  Modified:
%
%    21 July 2022
%
%  Author:
%
%    John Burkardt
%
%  Input:
%
%    integer MARBLE_NUM, the number of marbles.
%
%    integer DRAW_NUM, the number of marbles to draw.
%
%    integer COLOR_NUM, the number of colors.
%
%    integer COLOR_COUNT(COLOR_NUM), the number of marbles of each color.
%
%  Output:
%
%    integer DRAW_COLOR(COLOR_NUM), the number of marbles drawn,
%    of each color.
%
% rng ( 'shuffle' );
%
%  Randomly sample DRAW_NUM distinct integers from 1:MARBLE_NUM.
%
  if ( true )
    y = ksub_random2 ( marble_num, draw_num );
  else
    y = randsample ( marble_num, draw_num );
  end
%
%  Ascending sort Y.
%
  y = sort ( y );
%
%  Assume the balls are colored in order.
%  Count the balls of each color by counting integers between limits.
%
  draw_color = zeros ( color_num, 1 );
  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
