Hi,

Can we use the Ternary operator in constraints, instead of if-else? I tried using Ternary but the result is not as expected.

Here is an example code:

class cons_check; rand logic [1:0] a; rand logic [3:0] b; constraint cons{ solve a before b; b == (a<2) ? 2 : 3; //if (a<2) b == 2; //else b == 3; } endclass module tb(); cons_check cons_h = new(); initial begin cons_h.randomize() with{a == 1;}; $display("a = %0d, b= %0d",cons_h.a, cons_h.b); end endmodule

Output with Ternary: a = 1, b= 10

Output with if-else: a = 1, b= 2