Part 3 · Constraint Randomization · Intermediate

Constraint Operators & Expressions

Hub — inside, dist, implication, solve...before, soft constraints, and functions in constraints.

Overview

Constraints are declarative — you describe the legal solution space and the solver picks a point inside it. Every operator in this topic shapes that space differently: inside carves out membership sets, dist adds probability weights on top of membership, -> links fields conditionally, solve...before reshapes the distribution without changing the set, and soft provides defaults that yield to harder requirements.

This is the single most interview-dense topic in SystemVerilog. Interviewers probe whether you understand solver semantics — that all constraints solve simultaneously and bidirectionally, that weights and sets are different things, and that ordering hints change probability, not legality. Memorized syntax without that model fails the follow-up questions.

Sub-topics

  1. inside, Ranges & Set Membership — set carving, negation, $ open ranges, arrays as sets.

  2. dist: Weighted Distributions — := vs :/ with exact probability math.

  3. Implication -> and if/else — truth-table reasoning and bidirectional solving.

  4. solve...before — distribution shaping with before/after probability diagrams.

  5. soft Constraints — overridable defaults and discard ordering.

  6. Functions & Operators in Constraints — function-call ordering, modulo/division traps, enums.

diagram
CONSTRAINT OPERATOR TOPIC MAP

  What is LEGAL? (solution set)          How LIKELY? (distribution)
  ───────────────────────────────       ────────────────────────────
  inside {[lo:hi], v1, v2}               dist { v := w, [a:b] :/ w }
  !(x inside {...})                      (also constrains the set!)
  a -> b   (implication)                 solve a before b
  if (a) b; else c;                      (reshapes probability only)
  soft x == v  (yields under conflict)
  func(args) in expressions
        │                                       │
        └───────────────┬───────────────────────┘
                        ▼
              CONSTRAINT SOLVER
     · gathers ALL active constraints (class + inline)
     · solves SIMULTANEOUSLY and BIDIRECTIONALLY
     · uniform over solution space unless dist / solve-before
     · no solution anywhere  randomize() returns 0

Key takeaways

  • Constraints define a solution space; the solver picks uniformly unless told otherwise.

  • dist and solve...before shape probability; inside and -> shape legality.

  • All active constraints solve together — there is no top-to-bottom execution order.

  • Interview follow-ups always probe the solver model, not the syntax.