Hi,
I have some difficulty to constrain an dynamic array to get even distribution on each element.
Can somebody help me how to write a constraint so that the 8 elements can evenly distribute?
As the code posted,
I got
'{EE0, EE2, EE3, EE1, EE3, EE0, EE3, EE0}, which is not the goal. The goal is to have 2 EE0, 2 EE1, 2 EE2, 2 EE3.
typedef enum bit[1:0] {EE0, EE1, EE2, EE3} ee_e;
class A;
rand ee_e EEs[];
constraint EEs_sz {
EEs.size == 8;
}
constraint EEs_even {
EEs.xor() == 0;
EEs.sum with(int'(item)) == 6*2;
EE0 inside {EEs};
EE2 inside {EEs};
}
function void print_it();
$display("%p",EEs);
endfunction // print_it
function void randomize_it();
this.randomize();
void'(print_it());
endfunction // randomize_it
endclass // A
module tb;
A a;
initial begin
a = new();
a.randomize_it();
end
endmodule // tb