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 `:/`)
      • Case A vs Case B vs Trap Variant
      • Small Range with := vs Large Range with :/
      • Soft Constraint Priority (a soft puzzle in the dist section)
      • dist After Hard Pruning
      • Boolean dist Cascading into Value dist
      • Zero Weight Means Never Chosen
    • solve...before Bias Puzzles
    • 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

←Distribution Puzzles (`dist`, `:=` vs `:/`)
  1. Topics
  2. DV Interview Puzzles
  3. Randomization & Constraint Puzzles
  4. Distribution Puzzles (`dist`, `:=` vs `:/`)
  5. Boolean dist Cascading into Value dist
On this page

    VLSI DV Interview PuzzlesAll levels

    Boolean dist Cascading into Value dist

    Use the usual 'dist is the marginal' reading: the dist on is_err sets P(is_err), and the dist on code only shapes code within the branch. Compute P(code==0) and P(code==501).

    Puzzle

    Difficulty: Medium · Puzzle 5 of 6 · Topic: Distribution Puzzles (`dist`, `:=` vs `:/`)

    Use the usual 'dist is the marginal' reading: the dist on is_err sets P(is_err), and the dist on code only shapes code within the branch. Compute P(code==0) and P(code==501).

    Code

    design.sv
    1
    2
    3
    4
    5
    6
    7
    8
    9
    class err_code;
      rand bit is_err;
      rand int unsigned code;
      constraint c_prob { is_err dist {0 := 9, 1 := 1}; }
      constraint c_map {
        if (is_err) code dist { [500:503] :/ 4 };
        else        code == 0;
      }
    endclass

    Hint

    Use conditional probability: P(code=v)=P(branch)*P(v|branch).

    Step-by-step solution

    Diagram
    1) Reading used: the dist on is_err is its marginal, so P(is_err=1)=1/10 and P(is_err=0)=9/10.
    2) If is_err=0, code is deterministically 0.
    3) If is_err=1, [500:503] :/ 4 makes each of 500..503 equal at 1/4 (weight 1 each).
    4) Therefore P(code=0)=9/10.
    5) P(code=501)= (1/10)*(1/4)=1/40.

    Answer

    Answer: Under the marginal reading: P(code==0)=90% and each error code 500..503 is 2.5% (1/40), including 501.

    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). Computes both stated readings (is_err dist as the marginal vs. weights multiplied over joint tuples); the LRM does not pin this down, so the page states the reading. Verilator 5.048 legality only: is_err=0 always pairs with code 0 and is_err=1 with 500..503; no probability is asserted.

    Why candidates get it wrong

    The 9/10 and 1/40 answer rests on that stated reading, the reading assumed here; the LRM does not spell out joint semantics, and tools may differ. If you instead multiply the weights over the joint tuples, the legal tuples are (0,0) with weight 9 and (1,500..503) with weight 1 x 1 = 1 each, total 13, giving P(code==0)=9/13 and P(code==501)=1/13. Verilator 5.048 measured P(code==0)~0.90, consistent with the marginal reading. Always state which reading you assume.

    Interviewer follow-up

    How would you make all five outcomes {0,500,501,502,503} exactly uniform? Model answer: weight the branch by the number of outcomes in it: `is_err dist {0 := 1, 1 := 4}`. Then P(is_err=1)=4/5, each error code is 4/5 * 1/4 = 1/5, and code==0 is 1/5. If you instead declare the joint-weight reading, the tuples are (0,0) and four error tuples, so equal weights `{0 := 1, 1 := 1}` already give 1/5 each; the right answer depends on the reading you state.

    Say it out loud

    I would state my reading first: the dist on is_err is its marginal, so error has probability one tenth. When there is no error, code is forced to zero, so the probability that code is zero is nine tenths, and each error code from 500 to 503 is one fortieth, including 501. The trap is that the LRM does not spell out the joint semantics, so a tool that multiplies the weights over tuples would give nine thirteenths and one thirteenth instead. Next I would check what my target tool actually does, or weight the branch to avoid the ambiguity.

    Related topics

    • dist: Weighted Distributions

    • Wrong Distribution Debugging

    • Back to Distribution Puzzles (`dist`, `:=` vs `:/`)

    • Randomization & Constraint Puzzles section

    Previous

    96 / 293

    Next: Zero Weight Means Never Chosen

    Up next

    Up nextZero Weight Means Never Chosen

    Sign in to save progress

    Practice this lessonPrevious lessonReport an error

    See also

    • Case A vs Case B vs Trap Variant
    • Small Range with := vs Large Range with :/
    • Soft Constraint Priority (a soft puzzle in the dist section)