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

AboutRoadmapCareersInternshipsFAQContactPrivacyTerms
Skip to lesson

Course contents

  • How to Use This Puzzle Bank
  • SystemVerilog Language Puzzles25
  • Difficulty Guide
  • Full Topic Map
  • Interview-Day Tips
  • Study Route: One Week Before the Interview
  • Study Route: Two Weeks
  • Study Route: Four Weeks (Full Course)4
  • OOP & Testbench Puzzles25
  • Concurrency & Timing Puzzles25
  • Randomization & Constraint Puzzles25
    • Constraint Solving Order Puzzles
    • Distribution Puzzles (`dist`, `:=` vs `:/`)
    • solve...before Bias Puzzles
      • Classic a->b Bias Shift
      • Three-Branch Kind Selection
      • Reverse Bias with solve b before a
      • m<n Cardinality Bias
      • Mode Branch Collapse Under Extra Relation
      • Three-Variable solve-before Chain
    • randomize() with Puzzles
    • Randomization & Constraint Puzzles: Tricky Q&A
  • SVA Assertion Puzzles25
  • Functional Coverage Puzzles25
  • Logic & Aptitude Puzzles25
  • Scenario & Debug Puzzles25
  • UVM Testbench Puzzles25
  • Clock, Reset & CDC Puzzles25
  • Bus and Interface Protocol Puzzles25
  • Interview Prep: Puzzle Rounds7
  • DV Puzzle Cheatsheet
Loading lesson

←solve...before Bias Puzzles
  1. Topics
  2. DV Interview Puzzles
  3. Randomization & Constraint Puzzles
  4. solve...before Bias Puzzles
  5. m<n Cardinality Bias
On this page

    VLSI DV Interview PuzzlesAll levels

    m<n Cardinality Bias

    Compute P(n==4) without solve-before, then the exact value with solve n before m.

    Puzzle

    Difficulty: Easy · Puzzle 4 of 6 · Topic: solve...before Bias Puzzles

    Compute P(n==4) without solve-before, then the exact value with solve n before m.

    Code

    design.sv
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    class sb_mn;
      rand int unsigned n;
      rand int unsigned m;
      constraint c {
        n inside {[1:4]};
        m inside {[0:3]};
        m < n;
      }
      // Variant: solve n before m;
    endclass

    Hint

    Count legal m values for each n.

    Step-by-step solution

    Diagram
    1) n=1 allows m={0} (1 tuple), n=2 allows {0,1} (2), n=3 allows {0,1,2} (3), n=4 allows {0,1,2,3} (4).
    2) Total tuples = 1+2+3+4 = 10.
    3) Baseline P(n==4)=4/10=0.4.
    4) With solve n before m, n is chosen first, uniformly over the values that have a legal completion; all four values (1..4) do, so P(n==4)=1/4 exactly, then m is uniform over its legal values.
    5) Legal solutions are unchanged.

    Answer

    Answer: Without solve-before, P(n==4)=2/5 (40%); with `solve n before m`, P(n==4)=exactly 1/4 (n uniform over 1..4); the 10 legal tuples are unchanged.

    How this was checked

    Checked by running a model of the rule in a Python model and Verilator 5. Exact enumeration of the constraint set per the LRM (the LRM defines the distribution; simulator solvers need not be uniform). n has 1,2,3,4 legal m values; solve n before m makes n uniform over 1..4. Verilator 5.048 legality only: every result satisfies m < n within the stated ranges.

    Why candidates get it wrong

    Saying 'n is uniform because its domain is 1..4' is only true after solve n before m. Without it n is biased towards 4 by the m<n coupling (1:2:3:4 tuples). With it, the small-n cases (only 1 tuple) are over-represented relative to tuple counting.

    Interviewer follow-up

    Without solve-before, how would you still get n uniform? Model answer: randomize in two steps, `randomize(n) with { n inside {[1:4]}; }`, then `n.rand_mode(0)` and `randomize(m)` with m<n, but only on a fresh object. During the first call m is a state variable and `m < n` is still active, so a stale m biases n (after a round with m=3, n can only be 4 next time). Set `m = 0; n.rand_mode(1);` first, or simply use `solve n before m;`, which is LRM-defined and needs no state handling. (`n dist {1:=1,2:=1,3:=1,4:=1}` also works under the marginal reading, but is tool-dependent.)

    Say it out loud

    Counting tuples, n equal to one allows one m, two allows two, three allows three and four allows four, ten tuples in total, so without solve-before the probability that n is four is four tenths. With solve n before m, n is chosen first, uniformly over one to four, so the probability that n is four is exactly one quarter, and m is then uniform below n. The trap is calling n uniform without the solve-before; the m less than n coupling biases it toward large values. Next I would check that the legal set is still ten tuples.

    Related topics

    • Implication, if/else and solve...before

    • The Solution-Space Mental Model

    • Back to solve...before Bias Puzzles

    • Randomization & Constraint Puzzles section

    Previous

    101 / 293

    Next: Mode Branch Collapse Under Extra Relation

    Up next

    Up nextMode Branch Collapse Under Extra Relation

    Sign in to save progress

    Practice this lessonPrevious lessonReport an error

    See also

    • Classic a->b Bias Shift
    • Three-Branch Kind Selection
    • Three-Variable solve-before Chain