SV contraint to repeat elements n time

In reply to ak_verifsj:

//How do i create an dyn array with repeating elements n time. For eg in a[20] - 1 should be 10, 2 should be 5, 3 should be 5 times
module tb;
class Packet;
  rand int a[];
 
  constraint a_c {a.size == 20;
 
                       foreach (a[i]) a[i] inside {1,2,3};
                       //   a[i] dist{(a[i] == 1):= 10, (a[i] == 2) := 5, (a[i] == 3) := 5};} // this doesn't work for some reason, CAn some one explain?
  
                       a.sum() with ((item == 1) ? 1 :0) == 10;
                       a.sum() with ((item == 2) ? 1:0)  == 5;
                       a.sum() with ((item == 3) ?1 : 0) == 5;
                      }
  endclass
 
initial begin
  Packet p1;
  p1 = new();
  
  if (!p1.randomize()) begin
    $display ("Randomization Error");
  end
 
  $display ("Value of array A is %p",p1.a);

 
end
endmodule