Hi,
I have the below code which throws an error saying “Illegal non-integral expression in random constraint”. I understand the error as unpacked array is not a integral expression. but can some body show me the code to define a separate array and then use foreach loop to break the aggregate constraint to set of integral constraint. appreciate the help !
class hello_world #(int p);
rand bit [7:0] a [0:3][0:3];
// int p;
constraint c1 {
foreach(a[i,j]) {
a.sum with (item.index(1) == i ? int'(item): 0) == 27; // rows
a.sum with (item.index(2) == j ? int'(item): 0) == 27; // cols
}
a.sum with (item.index(1) == item.index(2) ? int'(item) : 0) ==27; // diag1
a.sum with ( (item.index(1) + item.index(2)==2) ? int'(item) : 0) ==27; // diag2
}
function void display ();
$display ("The value of array is %p",a);
endfunction
function new ;
// p =15;
endfunction
endclass
module test;
hello_world #(27)m1;
initial begin
m1=new();
m1.randomize();
m1.display();
end
endmodule