VLSI DV Interview Puzzles · All levels

Small Range with := vs Large Range with :/

Compute P(x==0) and P(x==7).

Puzzle

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

Compute P(x==0) and P(x==7).

Code

systemverilog
class dist_mix1;
  rand int unsigned x;
  constraint c {
    x dist { [0:1] := 4, [2:9] :/ 4 };
  }
endclass

Hint

The second range has 8 values, so :/ splits the total weight across 8.

Step-by-step solution

diagram
1) Values 0,1 each get weight 4 from :=.
2) Values 2..9 each get weight 4/8=0.5 from :/.
3) Total weight = 2*4 + 8*0.5 = 12.
4) P(x==0)=4/12=1/3.
5) P(x==7)=0.5/12=1/24.

Answer

Answer: P(x==0)=1/3 (~33.33%) and P(x==7)=1/24 (~4.17%).

Why candidates get it wrong

Candidates often incorrectly give both ranges equal per-value probability because both clauses use weight 4.

Interviewer follow-up

If [2:9] changes to :=4, what does P(x==7) become?

Related topics