hello
My question is I want to randomize a 2-d dynamic array but the problem is how to give two different constraints for two dimensions
for example
rand logic data;
I want the data width to be between 0 to 32 whereas the depth should be between 1 to 10
As I mentioned that it is for UVM, How do i randomize the 2-d array declared in sequence_item in the test case
In reply to duggi bhavya:
To clarify you have 2 unpacked dimensions in your dynamic arrayy. Is this what you want?
One index is the data_width and the other one is data_depth. Data_with and depth should be randomized. The content of your array doesn’t matter. Is this correct?
In reply to duggi bhavya:
Hi duggi bhavya,
If you want to randomize only data_width and depth for dynamic array. The content of array doesn’t matter for you, then you can use following code:
class abc;
bit logic_data;
rand int depth_size;
rand int width_size;
function void post_randomize();
logic_data = new[depth_size];
foreach(logic_data[i])
logic_data[i] = new[width_size];
endfunction
endclass
module tb_top;
abc a;
initial begin
a = new();
a.randomize() with {depth_size inside {[1:10]}; width_size inside {[16:32]};};
foreach(a.logic_data[i,j])
$display(“i:%0d j:%0d logic_data: %0d”,i,j,a.logic_data[i][j]);
end
endmodule
Kindly clarify your exact requirement.
Thanks
Mitesh Patel
In reply to mitesh.patel:
Or you can write constraint like this (if your simulator supports):
rand logic data[][];
constraint c_data {
data.size() inside {[1:10]};
foreach(data[i]) {
data[i].size() inside {[0:32]};
}
}
In reply to chr_sue:
yes that’s correct
In reply to chris_le:
Thank you it helped me