Randomize a 2-dimensional array to generate below pattern:

Hi
I have question about this

/*randomize a 2-dimensional array to generate below pattern:
                     1  2  3  4  5 
                     2  3  4  5  6
                     3  4  5  6  7
                     4  5  6  7  8
                     5  6  7  8  9  */

I complete my code but print in one line not in new line so can you help me. i have attached code and output for your ref.

Code :::

   module D20();

   class exp;

   randc bit [3:0]x[5][5];

   constraint array{foreach(x[i,j])
                    x[i][j]==j+i+1;} 
   endclass

   exp h_1;

   initial begin
     h_1 = new();
     assert(h_1.randomize());
     $display(" x =%p \n", h_1.x);
    end
   endmodule

///// Output //////

# run -all
#  x ='{'{1, 2, 3, 4, 5}, '{2, 3, 4, 5, 6}, '{3, 4, 5, 6, 7}, '{4, 5, 6, 7, 8}, '{5, 6, 7, 8, 9}}

but i want this every time new line with centre so please help me

In reply to Bharat.manvani:

replace the $display with following code:

  foreach(h_1.x[i])begin
    foreach(h_1.x[j])begin
      $write(h_1.x[i][j]);
    end
    $display("");
  end 

In reply to Bharat.manvani:

You can do either

 foreach (h_1.x[i]) $display(" x[%0d] =%p", i, h_1.x[i]);

or

  foreach (h_1.x[i]) begin
    foreach (h_1.x[,j]) $write("%4d", h_1.x[i][j]);
    $display;
  end

Thanks a lot…! That’s Working

12345
22345
33345
44445
55555 how to print this sequence using multidimensional array and constraints in system Verilog