VLSI DV Interview Puzzles · All levels
Boolean dist Cascading into Value dist
Compute P(code==0) and P(code==501).
Puzzle
Difficulty: Medium · Puzzle 5 of 6 · Topic: Distribution Puzzles (`dist`, `:=` vs `:/`)
Compute P(code==0) and P(code==501).
Code
systemverilog
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;
}
endclassHint
Use conditional probability: P(code=v)=P(branch)*P(v|branch).
Step-by-step solution
diagram
1) P(is_err=1)=1/10 and P(is_err=0)=9/10 from c_prob.
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.
4) Therefore P(code=0)=9/10.
5) P(code=501)= (1/10)*(1/4)=1/40.Answer
Answer: P(code==0)=90% and each error code 500..503 is 2.5% (including 501).
Why candidates get it wrong
Candidates often compute 1/4 for code 501 and forget the branch probability multiplier.
Interviewer follow-up
How would you make all five outcomes {0,500,501,502,503} exactly uniform?