I encounter a question: generate a 3x3 dynamic array with one of the value being highest of all.
I came up a complicated method, that will call a function which will use associate array count frequency and find max at the same time. Then set count(max) == 1. Running in simulation, looks like, rand variable cannot be used in function. So I do don't know how to achieve by now.
May I know if there is any easier way to do this?
In reply to aaaaaa:
class abc;
rand int unsigned dyn_array[][];
rand int unsigned highest_value_row;
rand int unsigned highest_value_col;
constraint c1 {
dyn_array.size == 3;
foreach(dyn_array[i]) {
dyn_array[i].size == 3;
}
}
constraint highest_value {
highest_value_row >=0 && highest_value_row <= 2;
highest_value_col >=0 && highest_value_col <= 2;
foreach(dyn_array[i,j]){
dyn_array[i][j] < 100;
if(i != highest_value_row && j != highest_value_col)
dyn_array[i][j] < dyn_array[highest_value_row][highest_value_col];
}
}
endclass
module abc;
initial begin
abc aa;
aa = new();
aa.randomize();
foreach(aa.dyn_array[i])begin
$display("%p, %d, %d, %d",aa.dyn_array[i], aa.highest_value_row,aa.highest_value_col,aa.dyn_array[aa.highest_value_row][aa.highest_value_col]);
end
aa.randomize();
foreach(aa.dyn_array[i])begin
$display("%p, %d, %d, %d",aa.dyn_array[i], aa.highest_value_row,aa.highest_value_col,aa.dyn_array[aa.highest_value_row][aa.highest_value_col]);
end
end
endmodule
May be this is what you are looking for from your description. See if this matches your requirements.