Hi,
can any one explain the constraint statement with sum().
i am not able to understand working of sum() call in below code.
module tb;
class cls;
rand int unsigned d;
rand int unsigned arr[10];
constraint arr_c{
foreach(arr[i]) { arr[i] inside {[1:10]};}
foreach(arr[i]) { arr.sum() with (int'(item==arr[i])) == (arr[i]==d ? 2:1);}
}
endclass
initial begin
cls obj = new;
int sum1;
repeat(5) begin
void'(obj.randomize());
sum1 = obj.arr.sum();
$display("d = %d, arr = %p sum = %d",obj.d,obj.arr,sum1);
end
end
endmodule
Thanks,
Zalak