Consider the below code.
class b;
rand bit A;
rand bit [1:0] B;
endclass
class c;
rand b arr[];
constraint constraints_c {
foreach(arr[i]) {
if(i>0) {
arr[i].B != retlastB(i);
}
}
foreach(arr[i]) {
if(i>0) {
//solve arr[i-1].B before arr[i].B;
<font size=20>solve arr[i-1] before arr[i]</font>;
}
}
}
function bit[1:0] retlastB(int idx);
for(int i = idx - 1; i >= 0; i--) begin
if(arr[idx].A == arr[i].A)
return arr[i].B;
end
return 0;
endfunction
function new;
arr = new[10];
foreach(arr[i])
arr[i] = new;
endfunction
endclass
The highlighed code doesnt compile. Without which anyways I get all incorrect randomization, without any warning of randomization fail from simulator. Each index of the random class (arr) depends on a previous history. Does anybody know a better way to accomplish this? I do not want to create a class with just one instance and iterate it 10 times preserving hostory thro postrandomize calls.