Creating unique values in array within a range of values


I want to create unique values in an array. I understand SV provides unique construct to do such a thing. However I want to constraint those array values further between 2 values.

class Nibbleset
   rand bit [3:0] nibbles[10];
   constraint uniq {unique {nibbles};}

Problem here is that values are constrained by size of each entry which is 4 bit. So each value can be between 0 and 15. if I want say unsized array or queue with randomized size and unique values between integer a and b, is there construct which comes with unique ?

rand logic [4:0] d_arr[$];
  constraint uniq {d_arr.size < 7;
                   unique {d_array}}

Something in 2nd code to say please choose value between 7 and 30 ?

In reply to aashishs2603:

You can use a foreach iterative constraint and the inside operator to constrain each element in a range. You should also use inside constrain the size of the array.

rand logic [4:0] d_arr[$];
  constraint uniq {d_arr.size inside {[1:7]};
                   unique {d_arr}};
                   foreach (d_arr[i]) d_arr[i] inside {[7:30]};

In reply to dave_59:

Thanks Dave. I used foreach and it worked. However I was thinking since unique was introduced to remove foreach from constraint is there any other method without foreach?

Also there is construct which I tried which should exclude values but it did not work. I still values being included

rand logic [4:0] d_arr[$];
const bit [4:0] excludes {0,1,2};
  constraint uniq {d_arr.size inside {1:7};
                   unique {d_array,excludes}};