Right Diagonal elements are zero’s in a 3*3 matrix
Just for an example:
1 2 0
3 0 4
0 5 6
This is the below SV constraint that I have written, got the expected output;
module m1;
class c1;
rand bit [3:0] array[3][3];
constraint c1{
foreach (array[a,b])
{
foreach (array[a]){
if (
(a==0 && b==2) ||
(a==1 && b==1) ||
(a==2 && b==0)
)
array[a][b] == 0;
else
array[a][b] !=0;
}
}
}
function void post_randomize();
$display("elements %0p", array);
$display("dimension %0d", $dimensions(array));
endfunction
endclass
c1 obj;
initial begin
obj = new;
repeat (1) begin
obj.randomize;
end
end
endmodule
================
Query : The above constraint looks like very directed way, like
first row, last column
second row, mid column
third row, first column
I was looking for generic way or any generic constraint other than this solution.
Any other alternative way, please suggest.
Thank You,