IMPORTANT NOTICE: Please be advised that the Verification Academy Forums will be offline for scheduled maintenance on Sunday, March 23rd at 4:00 US/Pacific.
Hi, how can I make sure each value gets randomized for at least once?
bit [1:0] data;
repeat (6) begin
assert (std::randomize(data) with {
// To make sure data gets 0, 1, 2, 3 at least once within 6 times
// e.g. You get 2, 2, 3, 1, 3, 0
});
end
module top;
parameter N = 7;
class A;
bit [1:0] array_have[] = {0,1,2,3};
bit [1:0] array_havent[int] = '{0:0,1:1,2:2,3:3};
rand bit [1:0] data;
int remaining = N;
constraint c{ data inside {array_have};
array_havent.num() == remaining ->
data inside {array_havent};
}
function void post_randomize();
array_havent.delete(data);
remaining--;
endfunction
endclass
A a = new;
initial repeat (N) begin
assert(a.randomize());
$display("%03d %p %03d", a.data, a.array_havent, a.remaining);
end
endmodule
6 numbers of 4 possibilities cannot be unique.
Although randc could be used to generate values that meet the constraints, it does not allow all possible solutions like what they gave as an example.