#include <iostream>
#include <vector>
#include <random>
#include <algorithm> // find
int randomExcluding(int N, const std::vector<int>& excluded) {
// If all numbers are excluded, return -1 or throw exception
if (excluded.size() > static_cast<size_t>(N + 1)) {
return -1;
}
std::random_device rd;
std::mt19937 gen(rd());
std::uniform_int_distribution<> dis(0, N);
int num;
do {
num = dis(gen);
} while (std::find(excluded.begin(), excluded.end(), num) != excluded.end());
return num;
}
int main() {
std::vector<int> excluded = {2, 5, 7};
int N = 14;
std::cout << randomExcluding(N, excluded) << " ";
}
/*
run:
12
*/