I want to make dynamic random value in constraint as below.
Please help me.
rand int busy_bit[];
rand int count;
// When I count busy_bit[] = 1, the number of sum should be equal to count.
// The expression could be
// foreach (busy_bit[i])
// sum += busy_bit[i]
// My goal is "sum == count"
constraint busy_bit_count{
......// How to express above condition in the constraint.....
}
You’ve considered a dynamic array. You should assign a range of sizes to the dynamic array or the required size. Then, you can use:
constraint c1 {busy_bit.sum == count} //to set the sum of elements in the array = count
constraint c2 {busy_bit.size inside {[25:50]};} //user needs the size of the array to be in the range 25-50 and the sum of elements in it should be equal to the value of count.
class busy_bit;
rand int busy_bit[];
rand int count;
constraint ab {
busy_bit.size == 5;
foreach (busy_bit[i]) busy_bit[i] inside {[5:10]};
busy_bit.sum() with (int'(item)) == count;
}
endclass
module test;
busy_bit m1;
initial begin
m1=new();
repeat (3) begin
assert(m1.randomize());
$display ("%p",m1.busy_bit);
$display ("%d",m1.count);
end end
endmodule