Skip to question
SystemVerilogDesignVerificationFirmwareArchitectureASIC Interview Questions→
/Interview questions/SystemVerilog Basic Constraint Interview Question

Q018·Free·Design Verification

SystemVerilog Basic Constraint Interview Question

Difficulty
Easy
Topic
Constraints
Language
SV
Interview prompt

Question

Which set exactly describes all possible values of x after a successful randomize()?

Provided context

Code to inspect

class C;
  rand int unsigned x;
  constraint c { x inside {[1:4]}; x != 3; }
endclass
Choose one

Answer choices

  1. A. {1, 2, 4}
  2. B. {0, 1, 2, 4}
  3. C. {1, 2, 3, 4}
  4. D. All unsigned integers except 3
Answer framework

Short answer

The attainable set is `{1, 2, 4}`. Both expressions in the constraint block must hold: membership limits `x` to the inclusive interval 1–4, and the inequality then removes 3. Declaring `x` unsigned does not reintroduce zero.

Why this reasoning works

SystemVerilog treats separate expressions in a constraint block as simultaneous requirements unless their syntax says otherwise. The `inside` expression admits the four integers from 1 through 4. Applying `x != 3` to those candidates filters out only 3, so a successful solve may select 1, 2, or 4.

The `int unsigned` declaration defines the variable’s full underlying domain, but that larger domain does not expand the values permitted by `inside`. Production testbench code should still inspect or assert the return value from `randomize()`, because later additions can make the complete constraint set unsatisfiable even though this small example has legal values.

Interview takeaways

  • Constraint expressions apply together
  • `inside` narrows the domain
  • Check `randomize()` success
Exact question handoffPractice Q018

Solve it in the question bank, keep your progress, and reveal the reviewed solution when your access allows.

Open in question bank →
Solution accessEach time you open this Solution, one Practice Credit is used; it is not permanently unlocked. Premium Solution content also uses one credit per opening.
Continue learning

Constraint Solver Fundamentals

Review randomization contracts, legal domains, soft constraints, and distributions.

  • Constraints
  • SystemVerilog
  • Constrained randomization
Constraint Solver Fundamentals →
Continue practicing

Related questions

Q286 · ConstraintsSoft constraintsEasyP→Q300 · ConstraintsDistribution constraintsMediumP→
ASIC.FYI · Learn silicon end to end.info@asic.fyi