I want to generate an array:
Sum of all array elements must be 17. Array must have at least one element which is multiple of 4. Size of an array can be anything.
My code is:
class fs_array;
rand bit[4:0] array1[];
constraint c1 { array1.sum() == 17;}
constraint c2 {array1[0][1:0] == 0;}
function void display();
$display("array1 = %p",array1);
endfunction
function void post_randomize();
array1.shuffle();
endfunction
endclass
The print is a null array. I commented out post_randomize and constraint c2 and found it is still with the same result. So I think error is from the sum. Can anyone help me how to make it work?