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
      • Implication vs Partitioned Branches
      • Bidirectional Solving of x+y==10
      • if-else with Overlap on One Value
      • randc Cycle with a Skipped Value
      • Width Wrap in a Sum Constraint
      • Array Size Coupled to Content
    • Distribution Puzzles (`dist`, `:=` vs `:/`)
    • 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

←Constraint Solving Order Puzzles
  1. Topics
  2. DV Interview Puzzles
  3. Randomization & Constraint Puzzles
  4. Constraint Solving Order Puzzles
  5. if-else with Overlap on One Value
On this page

    VLSI DV Interview PuzzlesAll levels

    if-else with Overlap on One Value

    Compute P(val==2) and P(mode==1) by counting legal tuples. Why is val not uniform over {1,2,3}?

    Puzzle

    Difficulty: Easy · Puzzle 3 of 6 · Topic: Constraint Solving Order Puzzles

    Compute P(val==2) and P(mode==1) by counting legal tuples. Why is val not uniform over {1,2,3}?

    Code

    design.sv
    1
    2
    3
    4
    5
    6
    7
    8
    9
    class overlap_if;
      rand bit mode;
      rand int unsigned val;
      constraint c {
        val inside {[1:3]};
        if (mode) val inside {1,2};
        else      val inside {2,3};
      }
    endclass

    Hint

    List legal (mode,val) pairs explicitly.

    Step-by-step solution

    Diagram
    1) mode=1 allows val {1,2} -> 2 tuples.
    2) mode=0 allows val {2,3} -> 2 tuples.
    3) Total legal tuples=4: (1,1),(1,2),(0,2),(0,3).
    4) val==2 appears in two tuples -> P(val==2)=2/4=1/2.
    5) mode==1 appears in two tuples -> P(mode==1)=1/2.

    Answer

    Answer: P(val==2)=1/2 and P(mode==1)=1/2; overlap on value 2 creates bias versus a naive 1/3-per-value assumption (val==1 and val==3 are 1/4 each).

    How this was checked

    Checked by running a model of the rule in a Python model. Exact enumeration of the constraint set per the LRM (the LRM defines the distribution; simulator solvers need not be uniform). Value 2 is reachable from both branches, so it owns two of the four (mode,val) tuples; solve val before mode makes val uniform.

    Why candidates get it wrong

    The value 2 is reachable from both branches, so it owns two of the four tuples. Reasoning on the val domain {1,2,3} alone hides that multiplicity; the legal set lives in (mode,val) space.

    Interviewer follow-up

    What small constraint would make val exactly uniform over 1,2,3? Model answer: add `solve val before mode;`. The legal set is unchanged (4 tuples), val is chosen first uniformly over its 3 feasible values (1/3 each), and mode is then 50/50 only when val==2 (forced to 1 for val==1, forced to 0 for val==3). P(mode==1) stays 1/2.

    Say it out loud

    I would list the legal pairs of mode and val: mode one gives val one or two, mode zero gives val two or three, so four pairs. Val equal to two appears in two of the four, so its probability is one half, and mode one is also one half. The trap is assuming val is uniform over one, two, three; the overlap on value two gives it double weight, and one and three get a quarter each. Next I would add solve val before mode if I wanted val uniform.

    Related topics

    • Implication, if/else and solve...before

    • The Solution-Space Mental Model

    • Back to Constraint Solving Order Puzzles

    • Randomization & Constraint Puzzles section

    Previous

    88 / 293

    Next: randc Cycle with a Skipped Value

    Up next

    Up nextrandc Cycle with a Skipped Value

    Sign in to save progress

    Practice this lessonPrevious lessonReport an error

    See also

    • Implication vs Partitioned Branches
    • Width Wrap in a Sum Constraint
    • Array Size Coupled to Content