Question on Array.Sum() Method , generate a n*n matrix such that there is only one 1's in a coloumn

In reply to sohels:
Not really Can you check once


class my_array;
  rand bit[4:0] array[2][10];
int i,j;
rand int n;

//This is first constraint limiting value of each item
constraint array_item_val {
foreach (array[i]) { // for each row
foreach (array[,j]) { // for each column in array
array[i][j] inside {[0:1]}; // each element is either 0/1
}
}
}

constraint array_col_sum {
  foreach (array[,j]) {
array.sum with (int'(array[item.index][j])) == 1; // col max sum is 1
}
}

function void display();
foreach (array[i]) begin
foreach (array[i][j]) begin
$write(" %d ",array[i][j]);
end
$display("\n");
end
endfunction

endclass

module my_array_randomization;
my_array ma;

initial begin
ma = new();
ma.randomize();
ma.display();
end
endmodule

vsim -voptargs=+acc=npr

run -all

0 0 0 0 0 1 0 1 0 0

1 1 1 1 1 0 1 0 1 1

is the output seen 1 1’s in a col