I’m trying to randomize a dynamic array as shown below. What I want to achieve is to randomize the array (burst_len) with given size (burst_cnt from plusarg), and all elements in the array add up to a give value (instr_cnt from plusarg). Each element should be larger than or equal to 2.
The following code couldn’t give me what I want. I need to add an extra constraint for each element. Couldn’t figure out why this constraint is needed.
int burst_cnt = 10;
int instr_cnt = 100;
int unsigned burst_len[];
std::randomize(burst_len) with {
foreach (burst_len[i]) {
burst_len[i] >= 2;
**//burst_len[i] <= instr_cnt;**
}
burst_len.sum() == instr_cnt;
burst_len.size() == burst_cnt;
};
for (int i=0; i<burst_len.size(); i++)
$display("burst_len[%0d] = %0d", i, burst_len[i]);
Correct. It is a solution, just not the one you were expecting. You need to add constraints to narrow the solution space, or choose data types and expressions that won’t overflow.