Array constraint. Each row total should be 100, with each element less than 80. I want to understand how to do this using only sum method of array

In reply to vickydhudashia:

What you need is some thing like below


class fs_array;
  rand bit [7:0] array1[3][4];
  int i,j;
  rand int n;
// ************************* incorrect output *******************************************
  constraint array_c   {     
    foreach  (array1[i]) {
      array1[i].sum(item) with ((int'(item)))== 100; // Gives sum of 100, pardon bracket error  if any
      }
  }     

  function void display();
    foreach (array1[i]) begin
      foreach (array1[i][j]) begin
        $write("  %d  ",array1[i][j]);
      end
      $display("\n");
    end
  endfunction
 
endclass
 
module fixedsize_array_randomization;
  fs_array pkt;
 
  initial begin
    pkt = new();
    pkt.randomize();
    pkt.display();   
  end
 
endmodule