This is not how I would usually solve a problem of this type, but maybe you can try out something like this to get just one combination (in pseudocode).
Let's assume that you can refer to objects as object[i][j], where i is the set index and j is the object index. In total, there are X^N combinations.
var result;
var sumPrevious;
for (var k = 0; k < Math.pow(x, N); k++) {
result = []; //array where we'll store one combination
sumPrevious = 0;
for (var i = 0; i < N; i++) {
objectIndex = Math.floor((k - sumPrevious) / Math.pow(x, N-i-1));
sumPrevious = sumPrevious + objectIndex * Math.pow(x, N-i-1);
result[i] = object[i][objectIndex];
}
if (result meets your criterion) {
return result; //return the first result that meets the criterion, which limits the number of iterations
}
}
I have not tested it, so I am not sure whether this code works. But the general principle is correct. Every combination is represented by a number from 0 to x^N-1 (k in pseudocode). Then I present this number as a 'base X' number. The 'digit' at each of the N places is the index of an object from each set. I check whether the combination meets the criterion and return the first combination that does.
An update. The function below, where the matrix parameter represents N sets of X objects, returns all possible combinations of objects. If you just return the first result that meets your criterion rather than push it to allCombinations array, you'll probably get the first combination you need.
var combinations = function(x, N, matrix) {
var allCombinations = [];
var result;
var sumPrevious;
for (var k = 0; k < Math.pow(x, N); k++) {
result = []; //array where we'll store one combination
sumPrevious = 0;
for (var i = 0; i < N; i++) {
objectIndex = Math.floor((k - sumPrevious) / Math.pow(x, N-i-1));
sumPrevious = sumPrevious + objectIndex * Math.pow(x, N-i-1);
result[i] = matrix[i][objectIndex];
}
allCombinations.push(result);
}
return allCombinations;
}