SystemVerilog dist: := vs :/ Weighted Distribution (With Worked Odds)

In short: dist makes some random values come up more often than others. := gives the weight to every value in a range, so a wider range gets more in total. :/ gives the weight to the range as a whole and splits it evenly. Weights are shares, not percentages. Other constraints always win over the weights.

Plain random treats every value the same.

But bugs live at the edges: the smallest packet, the biggest one, the FIFO that’s exactly full.

dist is how you tell the solver “pick these more often”.

Think of it like a raffle drum

Every value is a person in the room. The solver pulls one ticket out of a drum. More tickets means more chances.

  • **:= (each value):** every person in the group gets the full stack of tickets. A group of 3 with := 60 puts 180 tickets in the drum.
  • **:/ (the whole range):** the group shares one stack. A group of 3 with :/ 60 puts 60 tickets in the drum, 20 each.

Same number in the code. Very different drum.

Example 1: same numbers, two operators

// Same ranges, same numbers: := vs :/
class pick;
  rand bit [1:0] a;   // uses :=  (weight per value)
  rand bit [1:0] b;   // uses :/  (weight per range)
  constraint c_a { a dist { 0 := 40, [1:3] := 60 }; }
  constraint c_b { b dist { 0 :/ 40, [1:3] :/ 60 }; }
endclass

module tb;
  initial begin
    pick p = new();
    int ca[4], cb[4];
    repeat (10000) begin
      if (!p.randomize()) $error("randomize failed");
      ca[p.a]++;
      cb[p.b]++;
    end
    foreach (ca[i]) $display("value %0d   := %5d   :/ %5d", i, ca[i], cb[i]);
    $finish;
  end
endmodule

Output (10,000 runs, tested on Synopsys VCS 2025.06, 11 Nov 2026):

value 0   :=  1849   :/  4067
value 1   :=  2704   :/  1983
value 2   :=  2708   :/  2002
value 3   :=  2739   :/  1948
Value:= ticketsExpectedReal:/ ticketsExpectedReal
040 of 220~1,8181,84940 of 100~4,0004,067
160 of 220~2,7272,70420 of 100~2,0001,983
260 of 220~2,7272,70820 of 100~2,0002,002
360 of 220~2,7272,73920 of 100~2,0001,948

The real counts land within about 3% of the ticket math, and never exactly on it. That’s normal (see mistake 2).

  • With :=, value 0 is the least likely (18%).
  • With :/, value 0 is the most likely (40%).
  • Same code, flipped result. That’s why the operator matters.
Raffle drum picture: with := values 1 to 3 get 60 tickets each out of 220; with :/ they share 60 tickets, 20 each out of 100
Figure 1. Same numbers, two drums: := gives every value the full stack, :/ splits one stack.

Weights are shares, not percentages

Think of a recipe: 2 cups flour to 1 cup sugar. Double both and it tastes the same.

  • {0 := 1, 1 := 3} and {0 := 25, 1 := 75} give the same odds: 25% and 75%.
  • The weights don’t need to add up to 100. The solver divides each one by the total.

Weight 0 means never

A person with no ticket can’t win, ever. 5 := 0 doesn’t make 5 rare; it rules 5 out completely, like a hard constraint.

:= vs :/ at a glance

:=:/
Weight goes toEach valueThe whole range, split evenly
[1:3] := 60 / [1:3] :/ 6060 + 60 + 60 = 18020 + 20 + 20 = 60
Wider range meansMore total weightSame total, thinner per value
Raffle pictureEveryone in the group gets a full stackThe group shares one stack
On a single value (5 := 10 vs 5 :/ 10)Same thingSame thing
Use it whenEvery value in the range should be as likely as a single listed valueThe range as a group should get a fixed share

Working example 2: realistic packet lengths, plus the edges

// Realistic packet lengths, plus the two edges on purpose
class packet;
  rand int unsigned len;
  constraint c_len {
    len dist {
      1             := 5,    // smallest legal packet
      1500          := 5,    // largest legal packet
      [2:63]        :/ 60,   // mostly small
      [64:1023]     :/ 25,   // some medium
      [1024:1499]   :/ 5     // a few large
    };
  }
endclass

The drum holds 100 tickets in total, so the weights read as percentages here:

  • Length 1: 5% on its own. Length 1500: 5% on its own.
  • Small (2 to 63): 60% as a group, about 1% for each length.
  • Medium: 25%. Large: 5%.

If len were plain random over 1 to 1500, length 1500 would come up about once in 1,500 packets. Here it’s 1 in 20. That’s the whole point: edges on purpose, not by luck.

Stacked bar of packet lengths: 5 percent length 1, 60 percent 2 to 63, 25 percent 64 to 1023, 5 percent 1024 to 1499, 5 percent length 1500
Figure 2. Packet lengths: a realistic mix with both edges hit on purpose.

:/ is right for the ranges here. With :=, the medium range alone would hold 960 x 25 = 24,000 tickets and swamp everything else.

Working example 3: a knob the test can turn

Weights don’t have to be fixed numbers. Any non-random variable works, so one class can serve a clean test and an error test.

// A knob the test can turn: how often to inject a CRC error
class txn;
  int unsigned err_pct = 10;     // not rand: the test sets it
  rand bit     bad_crc;
  constraint c_err { bad_crc dist { 1 := err_pct, 0 := 100 - err_pct }; }
endclass

module tb;
  int pcts[3] = '{0, 10, 50};
  initial begin
    txn t = new();
    foreach (pcts[k]) begin
      int bad = 0;
      t.err_pct = pcts[k];
      repeat (10000) begin
        if (!t.randomize()) $error("randomize failed");
        bad += t.bad_crc;
      end
      $display("err_pct = %2d  ->  %0d bad CRCs out of 10000", pcts[k], bad);
    end
    $finish;
  end
endmodule

Output (10,000 runs, tested on Synopsys VCS 2025.06, 11 Nov 2026):

err_pct =  0  ->  0 bad CRCs out of 10000
err_pct = 10  ->  969 bad CRCs out of 10000
err_pct = 50  ->  6001 bad CRCs out of 10000
  • 0%: zero bad CRCs, as promised. Weight 0 means never.
  • 10%: 969 against 1,000 expected. Right on target.
  • 50%: 6,001, not about 5,000. An earlier 1,000-run test gave 587, so this is no fluke: on this simulator, a 50 / 50 split set this way leaned to about 60 / 40. The standard defines the weights, but how closely a simulator tracks them is up to its solver.

So in your own testbench, when a knob setting matters, count the results once on your simulator, just like this loop does. Don’t assume the percentage.

Think of a dimmer switch instead of an on/off switch. The test turns the knob; the class doesn’t change. At err_pct = 0, the 1 value has weight 0, so it’s never picked: a clean run, guaranteed.

Working example 4: dist meets a hard constraint

// dist plus a hard constraint: the hard one always wins
typedef enum {READ, WRITE, IDLE} op_e;
class bus_txn;
  rand op_e op;
  constraint c_mix { op dist { READ := 50, WRITE := 30, IDLE := 20 }; }
endclass

module tb;
  initial begin
    bus_txn t = new();
    int cnt[op_e];
    repeat (10000) begin
      if (!t.randomize() with { op != IDLE; }) $error("randomize failed");
      cnt[t.op]++;
    end
    foreach (cnt[o]) $display("%s  %0d", o.name(), cnt[o]);
    $finish;
  end
endmodule

Output (10,000 runs, tested on Synopsys VCS 2025.06, 11 Nov 2026):

READ  6211
WRITE  3789
  • IDLE never shows up. The with constraint is hard, and hard always wins.
  • The rest keep their ratio: 50 : 30 works out to 6,250 and 3,750, and the run gave 6,211 and 3,789. Picture IDLE’s people leaving the room before the draw: their tickets come out of the drum, everyone else’s stay.
  • The fine print: the standard only promises the weights when nothing else squeezes the variable. When constraints and weights truly clash, the solver only has to obey the constraints (Dave Rich explains this in a 2017 thread). So check the counts on your simulator.

Common mistakes (and the fix for each)

These come from real Verification Academy threads, retold in my own words with links.

1. The “95%” that came out as 16%

  • What happened: in 2024 someone wrote bar dist {[0:99] := 5, 100 := 95}; and expected 100 to come up 95% of the time. A LinkedIn post even called it a simulator bug (Verification Academy, 2024).
  • Why: := gives each of the 100 values weight 5. That’s 500 tickets for the range against 95 for the value 100. 95 out of 595 is about 16%.
  • Fix: [0:99] :/ 5. Now the range holds 5 tickets in total and 100 gets 95 out of 100.
  • Picture it: you meant to give a team of 100 people 5 tickets to share, but gave each of them 5.
Bar chart: with [0:99] := 5 the value 100 gets about 16 percent; with [0:99] :/ 5 it gets 95 percent
Figure 3. One character apart: := gives 100 about 16%, :/ gives it 95%.

2. Expecting an exact split

  • What happened: in 2017 an engineer used {0 := 25, 1 := 25}, ran 100 times and got 52 / 48 instead of 50 / 50 (Verification Academy, 2017).
  • Why: weights set the odds, not the result. Flip a coin 100 times and you rarely get exactly 50 heads. The split only gets close to the weights over many runs.
  • Fix: nothing to fix. If you truly need an exact count (say, exactly 25 writes in 100), build the list yourself and shuffle() it.

3. A constraint that quietly overrides the weights

  • What happened: in the same 2017 thread, adding read_write == 1 in another constraint turned a weighted 25 / 75 split into 1000 / 0 (Verification Academy, 2017).
  • Why: the weights are a wish; other constraints are rules. Rules win. A 2022 thread adds that inside doesn’t mean “uniform”, and the weights still apply to whatever values remain (Verification Academy, 2022).
  • Fix: when a distribution looks wrong, search for every constraint on that variable, including with blocks and child-class constraints.

If the hard constraints rule out every value in the dist ranges, the result is worse: randomize() fails outright. How to read that failure is covered in why SystemVerilog randomization fails.

4. dist in a foreach shapes each element, not the array

  • What happened: someone put arr[i] dist {...} inside a foreach and wanted the array as a whole to follow 20 / 60 / 20 (Verification Academy).
  • Why: foreach unrolls into one dist per element. Each element draws from its own drum. A small array can easily miss the target mix.
  • Fix: use a bigger array or more runs, or count the elements with sum() with constraints if you need exact numbers per bucket.

5. A range written backwards

  • What happened: in 2015 a range written high-to-low, [32'h320FF000:32'h3207FFFF], failed to solve on one simulator (Verification Academy, 2015).
  • Why: [a:b] must be low-to-high. Written backwards, the range is empty: a drum with no tickets.
  • Fix: always write [low:high]. The same thread notes that wrapping a dist in extra parentheses is illegal too.

dist vs randcase

  • **dist shapes the value** a random variable takes, inside the solver.
  • **randcase picks which branch of code** runs, outside the solver.
  • Use dist for fields of a transaction. Use randcase to choose between whole sequences of actions. More in randcase vs randsequence.

Every idea on this page, in one picture

IdeaPicture it as
distA raffle drum: more tickets, more chances
:=Every person in the group gets a full stack of tickets
:/The group shares one stack
Weights are sharesA recipe: double everything and it tastes the same
Weight 0No ticket at all: can never win
Hard constraintPeople leaving the room before the draw
Exact split never happens100 coin flips rarely give exactly 50 heads
dist in a foreachEach element draws from its own drum
Backwards rangeAn empty drum
Weight from a variableA dimmer switch the test can turn

FAQ

What is the difference between := and :/ in SystemVerilog?

:= gives the weight to every value in a range. :/ gives it to the range as a whole and splits it evenly. On a single value they’re the same.

Do dist weights have to add up to 100?

No. They’re relative. Each weight is divided by the total.

Is dist a hard or soft constraint?

Both, in a way. The value must be one of the listed values (hard), but the weights are only a preference that other constraints can override.

Can a dist weight be a variable?

Yes, any expression that isn’t random, like err_pct in example 3.

What does weight 0 do?

It rules that value out completely.

Can I use dist on a randc variable?

No. randc cycles through every value once before repeating, so weights don’t make sense there, and the standard doesn’t allow it.

References

  • IEEE 1800-2017, SystemVerilog standard: section 18.5.4 (distribution), 18.5.14 (soft constraints), 18.4.2 (randc).
  • Verification Academy forum threads linked in the mistakes section (accessed 11 Nov 2026).
  • Examples 1, 3 and 4 tested on Synopsys VCS 2025.06 on 11 Nov 2026. Expected counts worked out from the weight rules in section 18.5.4.

What to read next

2 Comments

  1. temp_q = a.find with (item == i);

    For i = 0, queue is empty. And it gets filled with all 0’s.
    For i =1, queue contains elements with all 0’s. After above array locator method execution isn’t queue will contain elements of both 0 and 1?

    Shouldn’t temp_q all elements be deleted after display statement?

Comments are closed.