VLSI DV Interview Puzzles · All levels

Case A vs Case B vs Trap Variant

Activate one constraint at a time. Compute per-value probabilities for Case A, Case B, and c_trap.

Puzzle

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

Activate one constraint at a time. Compute per-value probabilities for Case A, Case B, and c_trap.

Code

systemverilog
class dist_puzzle;
  rand int unsigned x;

  // Case A
  constraint c_a {
    x dist { [0:3] := 8, [4:7] := 8 };
  }

  // Case B
  constraint c_b {
    x dist { [0:3] :/ 8, [4:7] :/ 8 };
  }

  // Trap variant
  constraint c_trap {
    x dist { [0:1] := 10, [2:7] :/ 10 };
  }
endclass

Hint

Convert ranges to per-value weights before normalizing.

Step-by-step solution

diagram
1) Case A (:=): each value in 0..3 gets weight 8, each value in 4..7 gets weight 8 -> uniform 0..7.
2) Case B (:/): each range gets total weight 8 split over 4 values -> each value weight 2 -> again uniform 0..7.
3) Trap: values 0 and 1 each weight 10; values 2..7 each weight 10/6.
4) Trap total weight = 10+10+6*(10/6)=30.
5) Trap probabilities: P(0)=P(1)=10/30=1/3, and P(any of 2..7)= (10/6)/30 = 1/18.

Answer

Answer: Case A and B are both uniform (each value 1/8), while in c_trap values 0 and 1 are each 1/3 and each of 2..7 is 1/18.

Why candidates get it wrong

Memorizing syntax without converting to effective per-value weights causes wrong interview math.

Interviewer follow-up

What single operator swap makes c_trap close to uniform?

Related topics