I wrote a snippet to delete distinct elements of an array using array method

module test;
class abc;
rand int unsigned da[];
rand int unsigned res[$];
constraint distinct{da.size==10;}
constraint values { foreach(da[i])
                    da[i] inside {[1:20]};}
constraint req {foreach (da[i])
                if(i>0)
                da[i] > da[i-1];}


function void post_randomize();
res=da.unique();
for(int i=0;i<res.size;i++)
    for( int j=0;j<da.size;j++)
          begin 
              if(res.pop_front() == da[j]);
                  da.delete(j);
          end 
endfunction

endclass


abc a1;
initial 
begin 
  a1=new();
  assert(a1.randomize);
  $display("%p",a1.res);
  $display("%p",a1.da);
end 
endmodule

I’m getting an error telling that

"this.da.delete(j);"
  The above function/task call is done with more arguments than needed.

You declared “da” as a dynamic array, and the “delete” method does not accept any arguments. Here is a quote from IEEE Std 1800-2017:

The delete() built-in method clears all the elements yielding an empty array (zero size)

Only queues are designed to add/delete one element at a time. Dynamic arrays must be sized as a whole array.

It’s not clear what you are trying to accomplish with your non-functioning code. It’s not a good idea to iterate over an array as you are changing its size.

Yes, I understood it now.
What would be the best way to get an output for my question?

I do not understand your question. What do you mean by “distinct” in terms of elements of an array. Can you give me an input array example and output array you are expecting.

You can always copy a dynamic array to a queue, then delete the elements you want, then, copy it back to the dynamic array.