Constraint on array to get even distribution

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

In reply to mlsxdx:

2 ways to have hard distribution.



     typedef enum bit[1:0] {EE0=0, EE1, EE2, EE3} ee_e;

     // 1st method : simple way for your case
     EEs.sum with(int'(item==EE0)) == EEs.size/4;
     EEs.sum with(int'(item==EE1)) == EEs.size/4;
     EEs.sum with(int'(item==EE2)) == EEs.size/4;
     
     // 2nd method : to support more enum type if need
     rand ee_e EEs[];
     rand ee_e helper[4]; 

     foreach(helper[i]) {
       helper[i] == i;
       EEs.sum with(int'(item==helper[i])) == EEs.size/4;
     }


In reply to javatea:

Thanks for your reply, javatea.
The solution provided by you works.

It is good to know that EEs.sum with(int’(item==EE0)) return the number of item == EE0.

So for the code below:
EEs.sum with(int’(item==EE0)) == EEs.size/4;

the right-hand size EEs.size/4 is 2.
the left-hand size is the sum() with(int’(item==EE0)), which return the number of element EE0.