x dist { [1:10] :/ 50, 20 :/ 50 }. What is P(x == 5)? And with := instead?5% with :/, which shares 50 across ten values. About 9.1% with :=, which gives 50 to each value: 50 out of 550.
soft rule and a hard rule disagree. Which wins, and is the call an error?The hard rule wins, and the call succeeds. A soft rule is a default the solver drops rather than fail.
err -> code == 255 on an 8-bit code. How often is err set, and what fixes it?About once in 257 calls: err == 1 allows one code, err == 0 allows 256. solve err before code is the standard's fix; a dist on err states the share outright, and it is the fix that held on every tool this course measured.
inside answers which values are legal. dist answers how often each legal value appears, and values it leaves out become illegal. Neither can do the other's job.
Soft marks a default the solver may drop to satisfy hard rules; no ordering keyword is involved. solve...before orders the pick, which moves probability only, never legality.
The bench measures each answer: both weight forms over 2000 calls, a soft default beside a hard rule, and the skewed err bit with and without a dist.
class weights;
rand bit [4:0] a, b;
constraint c_a { a dist { [1:10] :/ 50, 20 :/ 50 }; } // :/ shares 50 across ten values
constraint c_b { b dist { [1:10] := 50, 20 := 50 }; } // := gives 50 to each value
endclass
class soft_order;
rand bit [7:0] x;
rand bit mode;
constraint c_soft { soft x inside {[10:20]}; }
constraint c_hard { mode -> x > 100; }
endclass
class skew;
rand bit err;
rand bit [7:0] code;
constraint c_skew { err -> code == 255; }
endclass
class skew_fixed extends skew;
constraint c_fix { err dist { 0 := 1, 1 := 1 }; } // state the share outright
endclass
P(x == 5): with :/ 4.5% (5% predicted), with := 9.3% (9.1% predicted)
soft default kept whenever mode == 0 (400 calls); dropped for the 0 calls with mode == 1
err == 1 in 1000: plain 2 (uniform over pairs: about 4), with a dist 502
PASS: :/ and := matched their arithmetic, hard beat soft, and a dist fixed the skewNotice the soft line: in 400 calls mode never came out 1. The hard rule mode -> x > 100 competes with the soft default, and Verilator kept the soft default every time by keeping mode at 0. Legal, but a test that needs mode == 1 has to ask for it.
Run with Verilator 5.048 (--binary --timing) on 2026-10-18; every bench printed the PASS line shown. Verilator prints a harmless WIDTHTRUNC warning for if (!obj.randomize()), because randomize() returns an int, and an UNSATCONSTR warning when a solve fails on purpose. Icarus 13 does not support constraints.
Over 2000 calls P(x == 5) measured 4.5% with :/ and 9.3% with :=, against 5% and 9.1%.