Hi all:
when there are numerous rand variable in constraint:
class xaction;
rand int num[5];
constraint c_num {
foreach (num[i]) {
if (i > 0 ) {
num[i-1] < num[i];
}
num[i] inside {[0:9]};
}
}
endclass : xaction
module top;
xaction x;
int last_is_9;
int repeat_num;
initial begin
repeat_num = 50000;
repeat (repeat_num) begin
x = new;
x.randomize();
if (x.num[4] == 9) last_is_9 ++;
end
$display("last_is_9 hits: %0d/%0d", last_is_9, repeat_num);
end
endmodule
output:
last_is_9 hits: 25260/50000
As we expected, the result in array is uniform distribution, but the posibility of last element x.num[4] is 9 with above 50%.
How to modify the constraint (don’t use user-defined function in post_randomize)can make the x.num[4] inside [4:9] with a reasonable posibility?
Thanks!