function [Xs, this] = randomOrGridXFeasiblePoints(this, N)
% Find up to N random [grid] points, or until there are no more
% grid points. 'this' is updated to reflect sampling without
% replacement for the grid.
%

%   Copyright 2016-2023 The MathWorks, Inc.

if doingGridsearch(this)
    Xs = [];
    % Add grid X-feasible points
    for i = 1:N
        [X, this] = gridXFeasiblePoint(this);
        if isempty(X)
            % No more free grid points.
            break;
        else
            Xs(i,:) = X;
        end
    end
else
    % Add random X-feasible points
    Xs = randomXFeasiblePoints(this, N);
end
end
