Efficient way to generate a variable

In reply to mr_2020:

You can write the constraint without the foreach loop using unique:

success = std::randomize(rnd_val) with { unique {rnd_val, reset_valQ}; };

But realize that’s just syntactic sugar for your original code, so both are O(n) by your definition.