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. constraint_mode Changes Pass/Fail

VLSI DV Interview Puzzles · All levels

constraint_mode Changes Pass/Fail

Call #1 disables c_secure. Call #2 enables it back. Which call passes?

On this page

    Puzzle

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

    Call #1 disables c_secure. Call #2 enables it back. Which call passes?

    Code

    design.sv
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    class sec_req;
      rand bit secure;
      rand bit [3:0] addr;
      constraint c_addr   { addr inside {[0:15]}; }
      constraint c_secure { secure -> addr[3] == 1'b1; }
    endclass
    
    sec_req s = new();
    s.c_secure.constraint_mode(0);
    assert(s.randomize() with { secure == 1; addr inside {[0:3]}; }); // Call #1
    
    s.c_secure.constraint_mode(1);
    assert(s.randomize() with { secure == 1; addr inside {[0:3]}; }); // Call #2

    Hint

    With secure==1 and c_secure enabled, addr[3] must be 1.

    Step-by-step solution

    Diagram
    1) Call #1: c_secure disabled, so secure==1 with addr 0..3 is legal -> pass.
    2) Call #2: c_secure enabled, secure==1 implies addr[3]==1 -> addr must be 8..15.
    3) Inline addr 0..3 conflicts with required 8..15, so intersection is empty -> fail.

    Answer

    Answer: Call #1 passes and Call #2 fails; enabling c_secure makes the inline addr range illegal for secure==1.

    Why candidates get it wrong

    Candidates forget disabled constraints are completely removed from the solve set.

    Interviewer follow-up

    What inline change makes Call #2 pass while keeping secure==1?

    Related topics

    • Back to randomize() with Puzzles

    • Randomization & Constraint Puzzles section

    Previous

    101 / 210

    Next: rand_mode(0) Freezes Value and Can Overconstrain

    Up next

    Up nextrand_mode(0) Freezes Value and Can Overconstrain

    Sign in to save progress

    Practice this lessonReport an error

    See also

    • Inline Implication Can Empty Intersection
    • if-else in with Clause
    • pre_randomize Assignment vs Solver and post_randomize Call Count