How to orchestrate individual elements of dynamic array based on the size?

Hello !

  1. Wanted to generate some random array patterns to be fed into my DUT.
  2. But based on the size of the dynamic array, some elements of the array are pre-defined.
  3. For eg, if size is 1 → value is 1, if size is 3 → value is {9,7,7}, and size is 7 the value never should be starting with 0 or 9 and if the size is eleven the value should always start with 1.
  4. Tried the below piece of code, but wondering if can it be done using any array reduction operator in a efficient manner ?


Sample Code:
module dynno;
    class dynno;
        rand int number[];

        constraint number_c {
            number.size inside {1,3,7,11};
            foreach(number[i]) number[i] inside {[0:9]};
        }

        constraint number_val_c {
            if (number.size == 1) {
                number[0] == 1; 
            }
            else if (number.size == 3) {
                number[0] == 9;
                number[1] == 7;
                number[2] == 7;
            }
            else if (number.size == 7) {
                !(number[0] inside {0,9});
            }
            else if (number.size == 11) {
                (number[0] == 1);
            }
        }

        function new();
            assert(this.randomize);
            $display("size: %0d, number: %p\n", number.size, number);
        endfunction: new 
    endclass: dynno 

    initial begin
        dynno tn = new();
    end
endmodule: dynno 


In reply to desperadorocks:

I didn’t look very hard, but I don’t see any pattern in the values you want that might make your constraints more efficient.

In reply to dave_59:

Hello Dave !

When I said pattern meaning, based on the size of array I wanted to set certain elements of the array with particular value.

Eg:

  1. If size of array is 1, the value of the single element should be 1.
  2. If the size is 3, then the 3 array element value should be 9,7,7.
  3. If the size is 7, then the first element shouldn’t be 0 or 9 or the first 3 elements of the 7 element array should be 9,7,7.
  4. And if the size of the array is 11, then the first element should always be 1.

So would like to know how to effectively set partial array elements with specific values. Is the above approach seems fine, or is there a way I can use some reduction operators.

In reply to desperadorocks:

I see nothing wrong with your current approach.