How to shuffle a 2D array in systemverilog?

This is related to below thread : Constraint elements in a 2D array to a particular number a particular number of times
Hi @dave_59
I tried the above problem as shown below. However, .shuffle() does not seem to work. Can you please tell how to shuffle() works in case of 2D array?
I tried solving this question as shown below:

class abc;
  rand bit[7:0] arr[4][4];
  
  constraint arr_c{
    foreach(arr[i,j]){
      arr[i][j] inside {[0:10]};
      arr[i].sum() with (int'(item == 8)) == 2;
    
    }
     // arr.sum() with 
  
  }
      function void post_randomize();
    arr.shuffle();
        foreach(arr[i,j]) 
          $display("value of array[%p][%p] = %p",i,j,arr[i][j]);
    endfunction   
  
endclass



  module tb;
   abc abc_inst;
  initial begin 
    abc_inst = new();
    //repeat(10)
    abc_inst.randomize();

  end
endmodule

I co not know what your expectation is, but shuffle works.
Look here

Thanks for the reply. The expectation is shuffling of elements among rows as well as columns. Currently, the elements are getting shuffled with a particular row.

Hi, Lalita,
Maybe you want this:

abc_inst.arr.shuffle();
foreach(abc_inst.arr[i]) abc_inst.arr[i].shuffle();

You need to stream (pack) the array into a single dimension, then shuffle that, the unpack it back into the multidimensional array

 function void post_randomize();
    bit [7:0] temp[] = {>>{arr}};
    temp.shuffle();
    {>>{arr}} = temp;
    foreach(arr[i]) 
      $display("value of array[%0d] = %p",i,arr[i]);
  endfunction