Skip to question and answer

Hardware interview practice

SystemVerilog dist Constraints Explained

MediumConstraintsMultiple choice

What probability does this distribution assign to x equal to 2?

Question code
rand int x;
constraint c { x dist { 0 := 1, [1:3] :/ 6 }; }

Answer choices

  1. A. 1/4
  2. B. 1/7
  3. C. 2/7
  4. D. 6/7

Concise answer

The answer and the key reason

The intended probability of `x == 2` is `2/7`. In a `:/` range entry, the stated weight belongs to the range as a whole. Splitting six shares among 1, 2, and 3 gives two each; zero contributes one more share.

Deeper explanation

Work through the implementation and tradeoffs

The distribution contains four legal values. The singleton entry for zero contributes one weight unit. The slash form on `[1:3]` apportions six units across the members instead of granting six units to every member. Thus each of 1, 2, and 3 carries weight two, making the numerator for `x == 2` equal to two.

Normalizing all weights gives `1 + 2 + 2 + 2 = 7`, so the target event receives two of seven total shares. This is a probability distribution, not a promise about the exact count in a short simulation run. Replacing `:/ 6` with `:= 6` would give each range member weight six, producing `6/19` instead.

What to remember

  • `:/` splits a range weight
  • Total weight is seven
  • Weights describe long-run probability

Practice the complete prompt

Explain it first, then compare the reviewed solution.

Open this exact question in the practice bank to attempt it, check your reasoning, and access the full member solution.Practice this question

Keep practicing

ConstraintsSystemVerilog Basic Constraint Interview QuestionConstraintsSystemVerilog Soft Constraints ExplainedConstraintsSystemVerilog solve before Constraint Semantics