Constraint question

Hi,

I intend to randomize the a and b values 500 times
condition:

  1. a should get unique values between 0 to 11
  2. if a= 1 then b should be 0 to 6. The value of b can repeat once it completes the full-cycle (0 to 6)

Code:

rand bit [3:0]  a;
randc bit [2:0]  b;
bit [2:0] arr [bit [3:0]] [$] ;

constraint a_c {a inside {[0:11]};
                           unique{a}; }

  constraint b_c { b inside {[0:6]};
	                      if(arr.exists(a))
	                         arr[a] != b ; }

  function void post_randomize();
    $display("Inside post_randomize");
    arr[a].push_back(b);
    if(arr.size() == 96)
	    a_arr[a].pop_front();
  endfunction

am getting below errors
Feature not yet implemented for assoc array exists() on a
variable-size multidimensional array Expression

The variable this.arr[a] is not an integral type.

Illegal aggregate comparison because arrays to be compared must be of
equivalent type.

Thanks in advance.

Hello,

//1. a should get unique values between 0 to 11
This doesn’t make sense if “a” is not an array. Every time “a” gets a value between 0 to 11, and your code “unique{a}” doesn’t have an impact here. If you meant, every time “a” should get a different value than before you can use a simple queue or “randc” would be perfect.

//2. if a= 1 then b should be 0 to 6. The value of b can repeat once it completes the full-cycle (0 to 6)

rand bit [3:0] a;
rand bit [2:0] b;
bit [3:0] arr[$]; // Why do you want to use queue of associative array? Is there something that you didn't mention in the problem statement?

constraint a_c { a inside {[0:11]}; 
   unique {arr,a};
}

constraint b_c {
   solve a before b; //since "b" has dependency on "a"
   if(a==1) 
       b inside {[0:6]};
 }

function void post_randomize();
$display(“Inside post_randomize”);
arr.push_back(a);
/*if(arr.size() == 96) // why 96 here?? */
if(arr.size() == 12) //"a" gets unique until all the values between 0-11 
   a_arr.pop_front();
endfunction