I think you have added constraint to have 2 bits position different than last address but there is no constraint on other bits so they will be random (same or different). Do you expect to have other bits random ?
// This code will be helpful for you
class A;
rand bit [31:0]a;
// static bit [31:0]a_temp;
static bit [31:0]aQ[$:10];
constraint a_a {$countones(a^const'(a))==2;}
// constraint a_a {$countones(a^a_temp)==2;}
constraint a_non_rep{unique{a,aQ};}
function void post_randomize();
// a_temp=a;
aQ.push_back(a);
endfunction
endclass
module top;
A b=new;
initial begin
for(int i=0;i<10;i++)begin
// b=new();
b.randomize();
$display("value of a=%b",b.a);
end
end
endmodule
I tried the pre_randomize method instead const. I observed that prev_addr initializes to 0. So if I want the addr to be between certain range say [200:800] constraint fails.
rand int addr;
int prev_addr;
function void pre_randomize();
prev_addr = addr;
endfunction
constraint c1{
addr inside{[200:800]};
addr == prev_addr +4;
}
Yes it will fail regardless of whether you use the const’(addr) cast or prev_addr mechanisms. You need to define how you want the series to start and what happens when addr+4 is greater than 800. For example you could do