Trying to solve a question : For a 8 bit variable if the past randomization resulted in a odd value, the next randomization should be even with 75% probability else be even with 25% probability. Write a constraint. Does my solution below seems correct?
class sample;
static bit[7:0] prev_data;
rand bit[7:0] data, temp_data_even, temp_data_odd;
rand bit odd;
rand bit even;
constraint c{
temp_data_even%2 == 0;
temp_data_odd%2 == 1;
(prev_data%2==1) -> data dist {temp_data_even := 75, temp_data_odd :=25};
(prev_data%2==0) -> data dist {temp_data_even := 25, temp_data_odd :=75};
}
function void post_randomize();
prev_data = data;
endfunction
endclass
module tb;
sample s = new();
initial begin
repeat(10) begin
s.randomize();
$display("%d",s.data);
end
end
endmodule