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