In reply to dave_59:
Hello Sir,
I think there are some mistakes in your code.
- Question demands to have a constraint that will make sure that any particular digit does not appear more than 2 times consecutively.
But the line you have written it’s assuring that any digit does not occur consecutively. - Another condition is like 2 3 4 is valid but 2 3 4 5 is not. Your code is checking something
else. ( digit[i-1]+1 != digit[i]+2 ) - why has this condition been made ?
I tried to make tiny little changes (using the if statement) in your code. Neither am I sure of my code is accurate and covers all cases nor am I getting your code.
Please look into it.
module top;
class A;
rand bit [3:0] digit[10];
constraint c {
foreach (digit[i]){
// decimal 1st
digit[i] <10;
// repetition 2nd
//i > 0 -> digit[i-1] != digit[i] ;
if(i>1 && digit[i]==digit[i-1])
digit[i]!=digit[i-2];
// sequence 3rd
//i > 1 -> digit[i-2] != digit[i-1]+1 && digit[i-1]+1 != digit[i]+2 ;
if(i>2 && digit[i]==digit[i-1]+1 && digit[i]==digit[i-2]+2)
digit[i]!=digit[i-3]+3;
//if(i>)
}
}
endclass
A a=new;
initial repeat (5) begin
assert(a.randomize());
$display("%p ",a.digit);
end
endmodule