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

AboutContactPrivacyTerms
Skip to lesson

Course contents

  • How to Use This Puzzle Bank
  • SystemVerilog Language Puzzles25
  • Difficulty Guide
  • Full Topic Map
  • Interview-Day Tips
  • 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
      • Three-Variable Implication Chain
      • Relational Pair Counting
      • 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
  • Interview Prep: Puzzle Rounds5
  • 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

VLSI DV Interview Puzzles · All 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}?

On this page

    Puzzle

    Difficulty: Medium · 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.

    Why candidates get it wrong

    People reason on variable domains separately and miss tuple multiplicity across condition branches.

    Interviewer follow-up

    What small constraint would make val exactly uniform over 1,2,3?

    Related topics

    • Back to Constraint Solving Order Puzzles

    • Randomization & Constraint Puzzles section

    Previous

    82 / 210

    Next: Three-Variable Implication Chain

    Up next

    Up nextThree-Variable Implication Chain

    Sign in to save progress

    Practice this lessonReport an error

    See also

    • Implication vs Partitioned Branches
    • Relational Pair Counting
    • Array Size Coupled to Content