function Y = labeling_rd(labels,n)

% Y = labeling_rd(labels,n)
% randomly label n samples that cover each class

np = length(labels);     % total number of points
u = unique(labels);
k = length(u);

idx = randperm(np);
idx2 = idx(1:n);
while length(unique(labels(idx2))) < k    % make sure to sample at least one for each class
    idx = randperm(np);
    idx2 = idx(1:n);
end

Y = zeros(np,k);
lbs = labels(idx2);
for i = 1:k
    Y(idx2(lbs==u(i)),i) = 1;
end


