Constraint

In reply to Ronak Patel:

How about this?


class dynamic_array;
 
  rand bit[3:0] myarray[];
 
  constraint sz{myarray.size==10;}
 
  constraint val{foreach(myarray[i]) myarray[i]==i;}
 
endclass

Both solutions answer your question. If there is something else that you are looking for, you need to provide more information so that others aren’t guessing what your requirements are.