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

  • Start Here6
  • SystemVerilog Language Foundations28
  • Object-Oriented SystemVerilog for Verification30
  • Constraint Randomization — Interview-Critical Deep Dive36
    • Randomization Basics: rand, randc & randomize()
    • Constraint Operators & Expressions
    • Dynamic Constraint Control
    • Randomizing Arrays and Queues
    • How the Constraint Solver Works
    • Debugging Randomization Failures
    • Interview Drills — Constraints and Randomization Q&A
      • Even/Odd, Alignment & Divisibility
      • Powers of 2, One-Hot & Bit Games
      • Unique Values & Ordering
      • Sum, Checksum & Distribution Drills
      • Dependent-Field Puzzles
      • Q&A: rand, randc & randomize()
      • Q&A: dist, inside, soft, solve-before
      • Q&A: Controlling Randomization
      • Q&A: Arrays & Nested Objects
  • SystemVerilog Assertions — Interview-Critical Deep Dive40
  • Functional Coverage in SystemVerilog22
  • Testbench Architecture in SystemVerilog23
  • Advanced Language & Integration25
  • Senior & Interview Preparation21
  • Principal-Level Verification28
Loading lesson

‹Interview Drills — Constraints and Randomization Q&A
  1. Topics
  2. SystemVerilog
  3. Constraint Randomization — Interview-Critical Deep Dive
  4. Interview Drills — Constraints and Randomization Q&A
  5. Q&A: dist, inside, soft, solve-before

Part 3 · Constraint Randomization · Intermediate

Q&A: dist, inside, soft, solve-before

Revision: membership against weighting, soft priority, ordering, and skew.

On this page

    Why this matters

    Asked for P(x == 5) under a :/ range weight, a candidate gave the := answer. Both operators look alike, and the shares differ by almost half.

    After this lesson you can: compute dist shares for both operators, rank soft against hard rules, and explain and fix a skewed control bit.

    Note

    Revision page. Answer each question before opening it; the full lessons are inside, Ranges, dist: Weighted Distributions, Implication and solve...before, soft Constraints.

    Predict first x dist { [1:10] :/ 50, 20 :/ 50 }. What is P(x == 5)? And with := instead?

    5% with :/, which shares 50 across ten values. About 9.1% with :=, which gives 50 to each value: 50 out of 550.

    Predict first A soft rule and a hard rule disagree. Which wins, and is the call an error?

    The hard rule wins, and the call succeeds. A soft rule is a default the solver drops rather than fail.

    Predict first err -> code == 255 on an 8-bit code. How often is err set, and what fixes it?

    About once in 257 calls: err == 1 allows one code, err == 0 allows 256. solve err before code is the standard's fix; a dist on err states the share outright, and it is the fix that held on every tool this course measured.

    Membership against weighting

    inside answers which values are legal. dist answers how often each legal value appears, and values it leaves out become illegal. Neither can do the other's job.

    Soft priority and ordering

    Soft marks a default the solver may drop to satisfy hard rules; no ordering keyword is involved. solve...before orders the pick, which moves probability only, never legality.

    The bench measures each answer: both weight forms over 2000 calls, a soft default beside a hard rule, and the skewed err bit with and without a dist.

    design.sv
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    class weights;
      rand bit [4:0] a, b;
      constraint c_a { a dist { [1:10] :/ 50, 20 :/ 50 }; }    // :/ shares 50 across ten values
      constraint c_b { b dist { [1:10] := 50, 20 := 50 }; }    // := gives 50 to each value
    endclass
    
    class soft_order;
      rand bit [7:0] x;
      rand bit       mode;
      constraint c_soft { soft x inside {[10:20]}; }
      constraint c_hard { mode -> x > 100; }
    endclass
    
    class skew;
      rand bit       err;
      rand bit [7:0] code;
      constraint c_skew { err -> code == 255; }
    endclass
    
    class skew_fixed extends skew;
      constraint c_fix { err dist { 0 := 1, 1 := 1 }; }       // state the share outright
    endclass
    
    Terminal
    P(x == 5): with :/ 4.5% (5% predicted), with := 9.3% (9.1% predicted)
    soft default kept whenever mode == 0 (400 calls); dropped for the 0 calls with mode == 1
    err == 1 in 1000: plain 2 (uniform over pairs: about 4), with a dist 502
    PASS: :/ and := matched their arithmetic, hard beat soft, and a dist fixed the skew

    Notice the soft line: in 400 calls mode never came out 1. The hard rule mode -> x > 100 competes with the soft default, and Verilator kept the soft default every time by keeping mode at 0. Legal, but a test that needs mode == 1 has to ask for it.

    Common pitfall

    Three confusions repeat: inside used for weighting, solve...before used for legality, and soft treated as a hard bound. Each swaps probability with legality.

    Interview

    The escalation to expect: the := and :/ numbers, then the skew demo, then why solve...before cannot rescue an empty set. Answer all three with probability-only language.

    Remember

    • inside is membership; dist is weighting.

    • :/ shares a weight across a range; := gives it to every value.

    • Hard beats soft, and the call still succeeds.

    Rule of thumb: answer probability questions in probability language, legality questions in legality language.

    How this was checked

    Run with Verilator 5.048 (--binary --timing) on 2026-10-18; every bench printed the PASS line shown. Verilator prints a harmless WIDTHTRUNC warning for if (!obj.randomize()), because randomize() returns an int, and an UNSATCONSTR warning when a solve fails on purpose. Icarus 13 does not support constraints.

    Over 2000 calls P(x == 5) measured 4.5% with :/ and 9.3% with :=, against 5% and 9.1%.

    Related topics

    • Q&A: Controlling Randomization

    Previous

    98 / 259

    Next: Q&A: Controlling Randomization

    Up next

    Up nextQ&A: Controlling Randomization

    Sign in to save progress

    Practice this lessonReport an error

    See also

    • Even/Odd, Alignment & Divisibility
    • Powers of 2, One-Hot & Bit Games
    • Unique Values & Ordering