Hi ,

I am trying to achieve a Constraint that Elements with Indexes greater than 1 have Value equal to sum() of elements less than that Index .

Eg : A[4] == A[0]+A[1]+A[2]+A[3]

Here is my Code :: I try calling a Function in Constraint but it fails

class A ; rand int unsigned a[] ; constraint DEPTH { a.size() == 10 ; } constraint VALUES { foreach(a[i]) { if ( i == 0 ) { a[i] == 0 ; } else if ( i == 1 ) { a[i] == 1 ; } else { a[i] == SUM(a,i) ; } } } function int unsigned SUM ( input int unsigned AA[] , int unsigned Index ) ; foreach(AA[i]) begin if ( i < Index ) begin SUM = SUM + AA[i] ; end end endfunction endclass A a1 ; initial begin a1 = new(); if ( a1.randomize() ) // Fails , But why ?? begin $display("Success with %p",a1); end end

Have 2 Questions :

[1] Why does it Fail ?

[2] Any alternate way ??

Thanks