function X = randomXFeasiblePointsForEachCategoricalLevel(this, N, catVarIdx)
% Generate N random initial points X per categorical level that satisfy the
% xConstraint. Return them in transformed space. catVarIdx is the index of
% the designated categorical variable in VarSpec.
%

%   Copyright 2016-2022 The MathWorks, Inc.

X = [];
catVarLB = this.PrivOptions.VarSpec.LBTrans(catVarIdx);
catVarUB = this.PrivOptions.VarSpec.UBTrans(catVarIdx);
catVarLBTrans = this.PrivOptions.VarSpec.LBTrans;
catVarUBTrans = this.PrivOptions.VarSpec.UBTrans;
for j = catVarLB:catVarUB
    catVarLBTrans(catVarIdx) = j;
    catVarUBTrans(catVarIdx) = j;
    XperLevel = bayesoptim.uniformPointsWithinBounds(this.PrivOptions.NumRestartCandidates, ...
        catVarLBTrans, catVarUBTrans);
    % Minimize the number of calls to isInputFeasible
    Idxs = [];
    for i = 1:size(XperLevel,1)
        if isInputFeasible(this, XperLevel(i,:))
            Idxs(end+1) = i;
            if numel(Idxs) == N
                break;
            end
        end
    end
    X = [X;XperLevel(Idxs,:)];
end
end
