VLSI DV Interview Puzzles · All levels
Zero Weight Means Never Chosen
Given this dist, what is P(x==0) and P(x==4)?
Puzzle
Difficulty: Medium · Puzzle 6 of 6 · Topic: Distribution Puzzles (`dist`, `:=` vs `:/`)
Given this dist, what is P(x==0) and P(x==4)?
Code
systemverilog
class zero_weight;
rand int unsigned x;
constraint c {
x dist { 0 := 0, [1:3] := 1, [4:5] :/ 2 };
}
endclassHint
Translate [4:5] :/ 2 into per-value weights first.
Step-by-step solution
diagram
1) x=0 has weight 0, so it is effectively excluded.
2) x=1,2,3 each get weight 1.
3) [4:5] :/ 2 gives each of 4 and 5 weight 1.
4) Total non-zero weight=5.
5) P(x==0)=0 and P(x==4)=1/5.Answer
Answer: x==0 is impossible (0%), and P(x==4)=20%.
Why candidates get it wrong
Some candidates think zero weight means 'rare' instead of 'never selected.'
Interviewer follow-up
Would adding x inside {[0:5]} change these probabilities?