In reply to fenil_shah:
That’s a different problem. Your puzzle only has a solution if NRow*SumRow == NCol*SumCol. Try
class hello_world;
rand bit [7:0] a [5][4];
constraint a_row {
foreach (a[i]) a[i].sum() with (int'(item)) == 40;
}
constraint a_col{
foreach (a[,j]) a.sum() with (int'(a[item.index][j])) == 50;
}
endclass
Or even more compactly
constraint a_r_c {
foreach (a[i,j]) {
a[i].sum() with (int'(item)) == 40;
a.sum() with (int'(a[item.index][j])) == 50;
}