I am trying write a constraint to generate this pattern 2, 33, 222, 5555, 22222, 777777, 2222222, 99999999, 2222222222 and so on
This is my constraint code
rand longint a;
int count=0;
constraint value {
//ODD
if(count%2 == 1)
a == odd(count);
//EVEN
else
a == even(count);
}
function void post_randomize();
count++;
endfunction
//ODD
function longint odd(int x);
longint num = 0;
int value = x+2;
for(int i=0;i <= x;i++) begin
num = num*10+value;
end
return num;
endfunction
//EVEN
function longint even(int x);
longint num=0;
for(int i=0;i <= x;i++) begin
num = num*10+1;
end
return 2*num;
endfunction
This is my output
#2
33
222
5555
22222
777777
2222222
99999999
222222222
12222222221
22222222222
1444444444443
2222222222222
166666666666665
222222222222222
The even pattern of 2s are coming properly.
But odd pattern is coming wrong