Specifying range of values in array

Hi,
A naive question from a SV enthusiast. I would like to declare an array(doesn’t matter if it’s queue/associative/dynamic array ) which should have all elements other then some specific value.

For example, an array which should have all possible 3 bit values other than 3’b010 and 3’b011, should look like :
array = {3’b000,30b001,3’b100,3’b101,3’b110,3’b111}

What’s the most efficient way to generate such array for large size (e.g. consider 32bit members in above example) inside a module?

Thanks.

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?

In reply to Tudor Timi:

Thanks Tudor, for descriptive answer. It was very helpful. Answer to your question: I am trying to explore possibilities of SV out of curiosity. Based on application, I would choose the implementation. I prefer to avoid unnecessary storage of large arrays if that is not helpful in given application.