Constraint: Random variable shows up as a constant in solver

Hello,
I’m running into a constraint solver problem where a “rand” variable shows up as a constant while solving the constraint.

Here is the code I’m using, along with the randomize command.

  class base;
  rand logic route_to_l1;
  rand logic [2:0] srfc_type;

  constraint essentials_c {
    srfc_type  inside {[0:6]};

    if (srfc_type inside {1, 4}) {
          route_to_l1 == 1;
    }
    else {
          route_to_l1 == 0;
    }
  }

Randomize statement:
base.randomize with {srfc_type == 0};

Error:
bit[0:0] route_to_l1 = 1’h1;
rand $unit::surftype_t srfc_type; // rand_mode = ON

I’m not able to understand why the var “route_to_l1” gets solved as a constant.
Seems like it solves this variable, before going to “srfc_type”, whereas it should go the other way.

When i write similar code on EDA playground, it seems to work.
range_constraint(1) - EDA Playground

**Question:

  1. When does a random variable show up as a constant in a solver?
  2. Is there a limit to the number of variables that can be solved together? The “srfc_type” var is a pivot for a lot of other variables in the class**

In reply to Prathamesh Shinde:

Using if/else in a constraint is effectively two implications.

srfc_type inside {1, 4} -> route_to_l1 == 1;
!(srfc_type inside {1, 4}) -> route_to_l1 == 0;

Since you are constraining
srfc_type
to be 0 using the with clause, then
route_to_l1
must also be 0 according to the second implication.

In reply to dave_59:

Dave,
I understand that. I expect that once I do a ‘randomize with srfc_type==0’ , then automatically route_to_l1 should become 0. (which is what you’re saying and that is the acceptable solution to me)

The constraint solver somehow starts with route_to_l1==1 and then cannot satisfy the with clause and fails with a “constraint error”

Also, I added another question to the original post.
2. Is there a limit to the number of variables that can be solved together? The “srfc_type” var is a pivot for a lot of other variables in the class

In reply to Prathamesh Shinde:

There might be a practical limit to the number of simultaneous random variables, but there is no restriction in the LRM. I think a tool would tell you that you hit a limit before reporting a constraint conflict, which is what you probably have. You’ll need to look at your tool’s User Manual for tips on how to debug constraint conflicts.