Hi,
I am trying to randomize a multi-dimensional array but it throws an error. Below is the code
class my_item;
typedef enum {ADD, SUB, DIV, MOV} inst_e;
rand int rand_arr[inst_e][inst_e];
inst_e op;
// Randomization constraints.
constraint k2 {
rand_arr.size() == op.num();
foreach(rand_arr[i]) rand_arr[i].size() == op.num();
foreach(rand_arr[i]) {
rand_arr[i][ADD] == 0;
rand_arr[i][SUB] == 1;
rand_arr[i][DIV] == 2;
rand_arr[i][MOV] == 3;
}
}
endclass
module automatic test;
function void run;
my_item item = new();
for (int i = 0; i < 1; i++) begin
$display("NORMAL RANDOMIZE %0d", i);
item.randomize();
end
endfunction
initial run();
endmodule
Error: The constraint solver failed when accessing a null array rand_arr[0].
Please make sure array rand_arr[0] is allocated properly.