Constraint existence of value into an array

In reply to nimrodw:
Either you can have named constraint and post_randomize method as below.

  constraint arr_c{
    foreach(arr[i]){
      if(i>3) arr[i]==0;
      else arr[i]==i;
    }
  }
  
  function void post_randomize();
    arr.shuffle();
  endfunction

Or you can covert the same logic to inline constraint.


some_object so=new(); 
assert(so.randomize(arr) with {foreach(arr[i]){
                                                if(i>3) arr[i]==0;
                                                else arr[i]==i;}
                                              }) so.arr.shuffle();
else $error("so.arr randomization is failed");