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. rand_mode(0) Freezes Value and Can Overconstrain

VLSI DV Interview Puzzles · All levels

rand_mode(0) Freezes Value and Can Overconstrain

Will randomize succeed? Explain the exact reason.

On this page

    Puzzle

    Difficulty: Medium · Puzzle 5 of 6 · Topic: randomize() with Puzzles

    Will randomize succeed? Explain the exact reason.

    Code

    design.sv
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    class rw_req;
      rand bit is_wr;
      rand bit [3:0] len;
      constraint c {
        if (is_wr) len inside {[1:4]};
        else       len inside {[8:12]};
      }
    endclass
    
    rw_req r = new();
    r.len = 10;
    r.len.rand_mode(0);
    assert(r.randomize() with { is_wr == 1; });

    Hint

    len is no longer randomized but still participates in active constraints.

    Step-by-step solution

    Diagram
    1) rand_mode(0) on len freezes len at current value 10.
    2) Inline sets is_wr=1, activating len inside 1..4.
    3) Frozen len=10 violates active constraint.
    4) No legal assignment exists, so randomize fails.

    Answer

    Answer: It fails 100%: len is fixed to 10 and cannot satisfy the is_wr==1 branch constraint len in [1:4].

    Why candidates get it wrong

    A frequent misconception is that rand_mode(0) also disables constraints that reference that variable.

    Interviewer follow-up

    How can you preserve len=10 and still make randomize pass?

    Related topics

    • Back to randomize() with Puzzles

    • Randomization & Constraint Puzzles section

    Previous

    102 / 210

    Next: pre_randomize Assignment vs Solver and post_randomize Call Count

    Up next

    Up nextpre_randomize Assignment vs Solver and post_randomize Call Count

    Sign in to save progress

    Practice this lessonReport an error

    See also

    • Inline Implication Can Empty Intersection
    • if-else in with Clause
    • foreach Inline Constraint on Dynamic Array