Is the number of values that are illegal greater than the number of values that are legal? I think the definition of “efficient” depends on this fact.
I’d guess the most straightforward way is to use ‘randomize()’:
randomize(array) with {
array.unique();
array.size() == 2 ** 32 - illegal_vals.size();
foreach (array[i])
!(array[i] inside { illegal_vals });
}
Another idea would be to generate all possible combinations (via counting) and remove the illegal values. If you store the set of all possible combinations properly (i.e. in an associative array, where the key is the same as the value), then additions and removals take constant time to perform (or possibly O(log(n)) depending on how associative arrays are implemented internally in the tool). You need N + size(illegal_vals) operations.
And the regular question: are you sure you need all values and don’t just need to perform some set-based operations that rely on whether values are legal/illegal?