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
    • Distribution Puzzles (`dist`, `:=` vs `:/`)
    • solve...before Bias Puzzles
    • randomize() with Puzzles
      • Inline Implication Can Empty Intersection
      • if-else in with Clause
      • foreach Inline Constraint on Dynamic Array
      • constraint_mode Changes Pass/Fail
      • rand_mode(0) Freezes Value and Can Overconstrain
      • pre_randomize Assignment vs Solver and post_randomize Call Count
    • 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

‹randomize() with Puzzles
  1. Topics
  2. DV Interview Puzzles
  3. Randomization & Constraint Puzzles
  4. randomize() with Puzzles
  5. if-else in with Clause

VLSI DV Interview Puzzles · All levels

if-else in with Clause

What len values are possible and with what probabilities under tuple counting?

On this page

    Puzzle

    Difficulty: Easy · Puzzle 2 of 6 · Topic: randomize() with Puzzles

    What len values are possible and with what probabilities under tuple counting?

    Code

    design.sv
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    class pkt;
      rand bit is_write;
      rand bit [3:0] len;
      constraint c_base { len inside {[1:8]}; }
    endclass
    
    pkt p = new();
    assert(p.randomize() with {
      is_write == 0;
      if (is_write) len inside {[1:2]};
      else          len inside {[7:8]};
    });

    Hint

    Given is_write==0, only else branch constrains len.

    Step-by-step solution

    Diagram
    1) Inline fixes is_write to 0.
    2) Therefore only else branch applies: len in {7,8}.
    3) Base len 1..8 intersects to {7,8}.
    4) Two legal tuples remain, so tuple-count gives 50/50 for len 7 and 8.

    Answer

    Answer: Only len=7 or 8 is legal, each at 50% under equal tuple weighting.

    Why candidates get it wrong

    Candidates sometimes enforce both if and else branches, which is incorrect.

    Interviewer follow-up

    If is_write were unconstrained, what is P(is_write==1) under tuple counting?

    Related topics

    • Back to randomize() with Puzzles

    • Randomization & Constraint Puzzles section

    Previous

    99 / 210

    Next: foreach Inline Constraint on Dynamic Array

    Up next

    Up nextforeach Inline Constraint on Dynamic Array

    Sign in to save progress

    Practice this lessonReport an error

    See also

    • constraint_mode Changes Pass/Fail
    • rand_mode(0) Freezes Value and Can Overconstrain
    • pre_randomize Assignment vs Solver and post_randomize Call Count