Skip to content
DenseChip
Learn
PracticeCode labInterview

DenseChip

Navigate

Menu

LearnPracticeCode labInterview

Tools

All toolsSV editorCode repoResume
DenseChip

Practice, courses, and chip-design tools in one focused workspace.

LearnPracticeCode labInterviewToolsLearning paths

© 2026 DenseChip

AboutRoadmapCareersInternshipsFAQContactPrivacyTerms
Skip to lesson

Course contents

  • How to Use This Puzzle Bank
  • SystemVerilog Language Puzzles25
  • Difficulty Guide
  • Full Topic Map
  • Interview-Day Tips
  • Study Route: One Week Before the Interview
  • Study Route: Two Weeks
  • Study Route: Four Weeks (Full Course)4
  • OOP & Testbench Puzzles25
  • Concurrency & Timing Puzzles25
  • Randomization & Constraint Puzzles25
    • Constraint Solving Order Puzzles
    • Distribution Puzzles (`dist`, `:=` vs `:/`)
      • Case A vs Case B vs Trap Variant
      • Small Range with := vs Large Range with :/
      • Soft Constraint Priority (a soft puzzle in the dist section)
      • dist After Hard Pruning
      • Boolean dist Cascading into Value dist
      • Zero Weight Means Never Chosen
    • solve...before Bias Puzzles
    • randomize() with Puzzles
    • Randomization & Constraint Puzzles: Tricky Q&A
  • SVA Assertion Puzzles25
  • Functional Coverage Puzzles25
  • Logic & Aptitude Puzzles25
  • Scenario & Debug Puzzles25
  • UVM Testbench Puzzles25
  • Clock, Reset & CDC Puzzles25
  • Bus and Interface Protocol Puzzles25
  • Interview Prep: Puzzle Rounds7
  • DV Puzzle Cheatsheet
Loading lesson

←Distribution Puzzles (`dist`, `:=` vs `:/`)
  1. Topics
  2. DV Interview Puzzles
  3. Randomization & Constraint Puzzles
  4. Distribution Puzzles (`dist`, `:=` vs `:/`)
  5. Soft Constraint Priority (a soft puzzle in the dist section)
On this page

    VLSI DV Interview PuzzlesAll levels

    Soft Constraint Priority (a soft puzzle in the dist section)

    Note: this one is about `soft` constraints, not `dist`; it sits here because it also changes which values are likely. Which len values are legal, and with what probability, for each of the four calls (A to D)? Assume equal probability among legal values.

    Puzzle

    Difficulty: Medium · Puzzle 3 of 6 · Topic: Distribution Puzzles (`dist`, `:=` vs `:/`)

    Note: this one is about `soft` constraints, not `dist`; it sits here because it also changes which values are likely. Which len values are legal, and with what probability, for each of the four calls (A to D)? Assume equal probability among legal values.

    Code

    design.sv
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    class soft_len;
      rand bit [3:0] len;
      constraint c_hard { len inside {[1:12]}; }
      constraint c_def  { soft len inside {[1:4]}; }
    endclass
    
    soft_len s = new();
    assert(s.randomize());                                          // Call A
    assert(s.randomize() with { len inside {[3:9]}; });             // Call B
    assert(s.randomize() with { len inside {[6:9]}; });             // Call C
    assert(s.randomize() with { soft len inside {[8:10]}; });       // Call D

    Hint

    A soft constraint is kept whenever it can be satisfied together with every hard constraint and every higher-priority soft constraint. It is not dropped just because an inline constraint exists.

    Step-by-step solution

    Diagram
    1) Call A: nothing conflicts with c_def, so it is kept: len in 1..4, four values, 1/4 each.
    2) Call B: the inline hard constraint [3:9] overlaps c_def in {3,4}, so the soft constraint can still be satisfied and is KEPT: len in {3,4}, 1/2 each.
    3) Call C: [6:9] and [1:4] do not overlap, so c_def cannot be satisfied and is discarded: len in 6..9, 1/4 each.
    4) Call D: both are soft; the inline soft has higher priority than the class soft. [8:10] and [1:4] conflict, so c_def is discarded: len in {8,9,10}, 1/3 each.
    5) A hard constraint is never discarded; if the inline in Call C had been outside 1..12 the call would fail instead.

    Answer

    Answer: A: 1..4 (1/4 each). B: {3,4} (1/2 each). C: 6..9 (1/4 each). D: {8,9,10} (1/3 each).

    How this was checked

    Checked by running a model of the rule in a Python model and Verilator 5. Exact enumeration of the constraint set per the LRM (the LRM defines the distribution; simulator solvers need not be uniform). Soft constraints are applied in priority order (inline soft, then class soft) and each is kept only if the remaining set stays non-empty. Verilator 5.048: 200 calls of each of A to D always succeed and stay inside the predicted legal set (frequencies are not asserted).

    Why candidates get it wrong

    Call B is the trap: the inline constraint does not 'override' the soft default. Soft means 'satisfy if consistent with the hard constraints', so a partial overlap shrinks the range to the overlap {3,4} instead of discarding the default. It is discarded only on a full conflict (Call C) or against a higher-priority soft (Call D). Legal sets for all four calls were confirmed on Verilator 5.048 (B gave only 3 and 4, C only values within 6..9, D only 8 to 10).

    Interviewer follow-up

    What does Call D become if the inline is `soft len inside {[3:9]}`? Model answer: len in {3,4}. The two soft constraints are compatible (overlap {3,4}), so neither is dropped and both apply, 1/2 each. Soft constraints only fall away when they cannot be satisfied.

    Say it out loud

    This is really about soft constraints: soft means satisfy it if it is consistent with the hard constraints. Call A has no conflict, so len is one to four. Call B overlaps in three and four, so the soft default is kept and len is three or four, half each. Call C does not overlap, so the default is discarded and len is six to nine; call D has a higher priority inline soft, so len is eight, nine or ten. The trap is thinking an inline constraint overrides the default in call B. Next I would check that the hard constraint is satisfiable, because a hard conflict fails the call.

    Related topics

    • soft Constraints

    • Inline Constraints: randomize() with

    • Back to Distribution Puzzles (`dist`, `:=` vs `:/`)

    • Randomization & Constraint Puzzles section

    Previous

    94 / 293

    Next: dist After Hard Pruning

    Up next

    Up nextdist After Hard Pruning

    Sign in to save progress

    Practice this lessonPrevious lessonReport an error

    See also

    • Case A vs Case B vs Trap Variant
    • Boolean dist Cascading into Value dist
    • Zero Weight Means Never Chosen