In reply to Subbi Reddy:
I googled a diagonal matrix and from what I was able to comprehend, except the diagonal elements none of the other values with unidentical index values store zero. And if indeed that is what you are looking for, here is the code:
class packet;
rand int array [] []; //two dimensional array size randomization
randc int size_i,size_j;
constraint size_set {size_i > 2 ; size_i < 7; size_j > 2; size_j < 7;}
constraint fixing_size {
array.size == size_i;
foreach(array[size_i]) {
array[size_i].size == size_j;
}
}
constraint array_elements_limit {
foreach(array[size_i,size_j]) {
if(size_i == size_j) {
array[size_i][size_j] == 1;
}
if(size_i != size_j) {
array[size_i][size_j] == 0;
}
}
}
constraint rows_equals_columns {size_i == size_j;}
endclass
module diagonal_array;
initial
begin
packet pkt = new();
repeat (5)
begin
pkt.randomize();
$display("\ni = %0d \t j = %0d",pkt.size_i,pkt.size_j);
$display("\narray : %0p",pkt.array);
$display("\n------------------------------------------------ END OF RANDOMIZATION -----------------------------------------------------");
end
end
endmodule