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. Inline Implication Can Empty Intersection

VLSI DV Interview Puzzles · All levels

Inline Implication Can Empty Intersection

For the shown randomize() call, does randomization always pass, always fail, or depend on solver luck? Explain pre/post hook behavior too.

On this page

    Puzzle

    Difficulty: Hard · Puzzle 1 of 6 · Topic: randomize() with Puzzles

    For the shown randomize() call, does randomization always pass, always fail, or depend on solver luck? Explain pre/post hook behavior too.

    Code

    design.sv
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    class txn;
      rand bit       is_write;
      rand bit [7:0] addr;
      rand bit [3:0] len;
      bit            lock_len;
    
      constraint c_base {
        addr inside {[0:255]};
        is_write -> (len inside {[1:8]});
        !is_write -> (len inside {[4:12]});
      }
    
      function void pre_randomize();
        if (lock_len) len = 4;
      endfunction
    
      function void post_randomize();
        if (is_write && (len > 8)) $error("illegal write len");
      endfunction
    endclass
    
    txn t = new();
    t.lock_len = 1;
    assert(t.randomize() with {
      is_write == 1;
      (addr inside {[16:31]}) -> (len inside {[9:12]});
    });

    Hint

    Inline with-clause is conjoined with class constraints, not overriding them.

    Step-by-step solution

    Diagram
    1) With is_write==1, class constraint requires len in 1..8.
    2) Inline implication can additionally require len in 9..12 when addr is 16..31.
    3) If solver picks addr in 16..31, constraints become unsatisfiable (len must be both 1..8 and 9..12).
    4) Solver can still satisfy by choosing addr outside 16..31, so call is satisfiable overall (not always fail).
    5) pre_randomize runs before solve but does not bypass constraints; post_randomize runs only on successful solve.

    Answer

    Answer: The call can succeed but not with addr in 16..31; successful outcomes force addr outside that range, and post_randomize executes only on those successful solves.

    Why candidates get it wrong

    Many candidates think inline constraints 'override' base constraints procedurally; they are logically ANDed.

    Interviewer follow-up

    How would you rewrite inline constraints to force success while keeping is_write==1?

    Related topics

    • Back to randomize() with Puzzles

    • Randomization & Constraint Puzzles section

    Previous

    98 / 210

    Next: if-else in with Clause

    Up next

    Up nextif-else in with Clause

    Sign in to save progress

    Practice this lessonReport an error

    See also

    • foreach Inline Constraint on Dynamic Array
    • constraint_mode Changes Pass/Fail
    • rand_mode(0) Freezes Value and Can Overconstrain