Count legal solutions, predict stimulus bias, preserve failing seeds, and reduce empty solution spaces without obscuring the original intent.
Shape the space of possible values.
A worked mechanism
Expected wait is not a coverage deadline
Even a reachable bin with fixed probability can stay empty after its mean waiting time.
A
One trial
12.5% per trial
Independent identical trials, each with hit probability p=1/8.
B
Mean first hit
8 trials
The geometric expectation is 1/p.
C
After 8 trials
34.36% still miss
Probability of still missing is (7/8)^8.
D
After 35 trials
99.07% have a hit
Probability of at least one hit is 1−(7/8)^35.
Compare each case under the stated assumptions; these are not sequential steps.
Work it through
Budget with a stated model
Eight trials is the mean waiting time, not a guaranteed closure point. Thirty-five independent trials exceed 99% probability of at least one hit.
Use the observed bin and its reachability evidence to close the requirement; do not mark it hit from this estimate.
Watch for this
These probabilities assume independent trials with unchanged p. randc, adaptive constraints, correlation, and unreachable bins invalidate this toy model.
Check your reasoning
Compute from the shown formula; record the actual seed and hits. Neither expectation nor confidence establishes behavioral correctness.
The language bench / constraints
Make the legal space visible.
rand bit type_a;
rand bit [1:0] val;
constraint c {
type_a -> val == 3;
val <= 3;
}
Question directory
Questions for Probability + debug
Open an authored answer, then use the surrounding visual and code example to test the rule.
SystemVerilog Solver probabilityCount solutions before predicting traffic.
Explain how legal-pair counts, solve before, weighted ranges, and rare events affect the stimulus distribution and the time required to reach coverage.
Concept model
Solve ordering changes sampling, not legality
Same legal solution setThree SHORT lengths, twelve LONG lengths
SHORT
LONG
kind == SHORT -> length inside {[1:3]}; kind == LONG -> length inside {[4:15]};
Marginal distributionSample complete pairs
3/15 = 20%SHORT
12/15 = 80%LONG
Sample complete legal pairs. LONG owns twelve pairs while SHORT owns three, so LONG is selected four times as often. All fifteen legal pairs remain available.
Both modes preserve the same legal pairs. Default sampling favors values with more compatible partners, while solve before chooses the ordered variable first.
Strong answer
With type_a as one bit and val as two bits, the legal pairs are (0,0), (0,1), (0,2), (0,3), and (1,3). In the uniform legal-pair model, type_a is 1 for one of five pairs, so its probability is 1/5.
Reason it through
The implication leaves all four val values legal when type_a is 0 but only one value legal when type_a is 1.
Adding solve type_a before val changes the marginal choice of type_a to roughly one half before selecting a compatible val.
A finite simulation fluctuates around the expected rate. Measure the distribution instead of expecting an exact count in every short run.
Strong answer
The inline hard restriction intersects the dist domain. The surviving values keep their relative bias and the solver normalizes probability over the reduced legal set.
Reason it through
If [8'h20:8'h7f] has total :/ weight 6 out of total weight 20, each of its 96 values has base probability 0.30 / 96.
Restricting that range inline to [8'h20:8'h3f] leaves 32 values from the same weighted item, so each surviving value has conditional probability 1 / 32.
With 70 percent base calls and 30 percent restricted calls, P(addr == 8'h20) is 0.7(0.30/96) + 0.3(1/32) = 0.0115625.
Strong answer
A bin hit with independent probability p has expected first-hit time 1/p. The chance it is still unhit after k tests is (1-p)^k, so rare bins dominate regression length.
Reason it through
Expected hits after n tests are np, with standard deviation sqrt(np(1-p)) for independent Bernoulli trials.
For target confidence c of at least one hit, choose k such that 1 - (1-p)^k >= c.
The n ln(n) coupon-collector estimate applies to many equally likely bins. Real coverage is usually governed by the least likely reachable bins and cross combinations.
Strong answer
If IDLE permits one length, SLOW permits three, and FAST permits seven, the legal-pair space has 11 assignments. Uniform sampling of complete pairs gives FAST seven of them, or about 63.6 percent.
Reason it through
IDLE contributes (IDLE,0), SLOW contributes three pairs, and FAST contributes seven pairs.
Adding solve mode before length selects among the three legal mode values first, making each mode roughly one third before a compatible length is chosen.
The legal set is unchanged by the ordering. Only the marginal sampling distribution changes.
Different modes own different numbers of legal pairssystemverilog
The hit count is binomial under independent identical trials. Its mean is np = 100/11, about 9.09 hits, and its standard deviation is sqrt(np(1-p)), about 2.87.
Reason it through
A single 100-test run is not expected to produce exactly nine hits. A rough two-standard-deviation band is about three through fifteen.
The binomial model assumes the probability remains fixed and trials are independent. Stateful randc variables, adaptive tests, and shared random state can violate that assumption.
Use measured coverage and confidence bounds to decide whether an observed deviation is meaningful rather than judging one short regression by eye.
Binomial result for one hundred trials at p equals one eleventh
Quantity
Formula
Result
QuantityMean
Formulanp
Result9.09 hits
QuantityVariance
Formulanp(1-p)
Result8.26
QuantityStandard deviation
Formulasqrt(np(1-p))
Result2.87 hits
QuantityApproximate 95% band
Formulamean ± 2 sigma
Resultabout 3 to 15 hits
SystemVerilog Patterns and solver debugMake failures small and reproducible.
Use hooks for procedural derivation, write structured collection problems clearly, and isolate an empty solution space without discarding the failing seed.
Concept model
Reconstruct the failure before changing the model
Failure evidenceReconstruct the exact model that returned zero
Seed and identitytest seed · object type · instanceProve you are replaying the same experiment.
Fixed object staterand_mode() · non-rand valuesFrozen values still participate in active rules.
The active hard relationships share no assignment.
Progressive isolationChange one thing, then preserve the evidence
01Confirm failurecheck the return bit
02Freeze the scenerecord state + modes
03Reduce the modeldisable one named block
04Prove the conflictre-enable one block at a time
rand_mode(0) freezes a variable; it does not remove its value from active constraints.A disabled block may reveal the conflict, but the requirement still needs a specification-backed repair.
Preserve the seed, object identity, fixed state, and active modes. Then reduce the model one named block at a time until the empty intersection is explainable.
Strong answer
Randomize the payload and an error-intent flag, compute correct parity procedurally in post_randomize(), then flip the parity only when the flag requests a negative test.
Reason it through
Keep the error intent as a named random field so its distribution can be covered and debugged.
Deriving parity after the solve avoids asking the solver to implement a reduction calculation that is naturally procedural.
The transaction should retain enough state to tell the scoreboard whether the corruption was intentional.
Controlled negative testingsystemverilog
class packet;
rand bit [31:0] data;
rand bit inject_error;
bit parity;
constraint error_rate_c {
inject_error dist {0:=99, 1:=1};
}
functionvoid post_randomize();
parity = ^data;
if (inject_error)
parity = ~parity;
endfunctionendclass
Strong answer
Constrain each start and finish pair locally, then relate each window to its predecessor with foreach. Add duration rules only for the indices that require them.
Reason it through
Local bounds establish start[i] < finish[i] and the global time limit.
For i > 0, start[i] >= finish[i-1] + gap simultaneously enforces ordering, non-overlap, and the minimum gap.
A modulus rule on finish[i] - start[i] expresses aligned durations without introducing a procedural loop.
Five ordered windowssystemverilog
localparam int N = 5;
rand int unsigned start[N];
rand int unsigned finish[N];
constraint windows_c {
foreach (start[i]) {
start[i] < finish[i];
finish[i] <=1000;
if (i > 0)
start[i] >= finish[i-1] + 8;
if ((i % 2) ==0)
((finish[i] - start[i]) % 4) ==0;
}
}
Strong answer
Preserve the failing seed and object state, confirm the return value, inspect fixed variables and active modes, then disable the smallest constraint blocks until the empty intersection becomes identifiable.
Reason it through
Print or record non-rand state, rand_mode(), constraint_mode(), inline conditions, and the exact object type before changing anything.
Re-enable one isolated block at a time and reduce the failure to a minimal set of conflicting expressions.
Use the simulator's solver diagnostics where available. Keep process-level procedural randomness and object randomization streams conceptually separate when reseeding.
Constraint failure isolation sequence
Step
Evidence to collect
Question answered
StepReproduce
Evidence to collectSeed, object type, fixed state
Question answeredCan the same model fail again?
StepInspect
Evidence to collectActive variables and blocks
Question answeredWhat actually entered the solve?
StepIsolate
Evidence to collectSmall block combinations
Question answeredWhich intersection is empty?
StepRepair
Evidence to collectSpecification-backed rule change
Question answeredWhich requirement was modeled incorrectly?
Strong answer
Constrain length to the legal aligned range, tie payload.size() to length, add the opcode implication, and compute the payload reduction with a width-safe contribution.
Reason it through
length inside {[64:1024]} plus length % 16 == 0 models the general size contract.
The opcode implication narrows length to 256 or 512 only for the special opcode; other opcodes keep the general domain.
A thousand-byte payload with a sum constraint is solver-heavy. If only parity matters, deriving or controlling one byte procedurally may be a clearer performance tradeoff.
Create a genuinely empty hard intersection, check that randomize() returns 0, then change one documented requirement at a time. A soft default may yield, but conflicting hard rules never override one another.
Reason it through
aligned == 1, size == 8, and addr inside 3 through 5 is impossible because none of those addresses is divisible by eight.
Disabling the named alignment block permits that negative scenario, but it also removes a legality guarantee and should be explicit in the test.
Alternatively, keep alignment active and use an inline range such as 0 through 15 with size 4. That hard inline range replaces the incompatible soft default and leaves legal aligned values.
Fail, isolate, then recover deliberatelysystemverilog
if (t.randomize() with {
aligned ==1;
addr inside {[3:5]};
size ==8;
}) $fatal(1, "expected alignment conflict");
t.align_c.constraint_mode(0);
if (!t.randomize() with { addr inside {[3:5]}; size ==8; })
$fatal(1, "negative scenario failed");
t.align_c.constraint_mode(1);
if (!t.randomize() with {
aligned ==1;
addr inside {[0:15]};
size ==4;
}) $fatal(1, "aligned recovery failed");
Strong answer
A process seed controls procedural calls made by that thread, while an object's random stream controls its constrained randomization. Reproducing a mixed testbench requires the original test seed, object creation order, and any explicit reseeding operations.
Reason it through
process::self().srandom(seed) affects calls such as $urandom(), $urandom_range(), and randcase in that process.
An object's srandom(seed) targets that object's random stream. In UVM, reseed() reapplies UVM's type-and-instance seeding policy rather than magically synchronizing the process stream.
Changing object names, construction order, fork structure, or the number of random calls can change later results even when the top-level seed is unchanged.
Keep each named block focused on one requirement, bound collection sizes, prefer direct declarative relationships, check every solve, and use coverage plus solver diagnostics as feedback.
Reason it through
Orthogonal named blocks make modes, inheritance, debug isolation, and specification review easier.
Avoid unnecessarily tight or redundant relationships and large unbounded collections. They enlarge or fragment the search problem without adding useful intent.
Document non-obvious probability choices, solve ordering, casts, and intentional constraint disabling so future tests preserve the same contract.
Constraint model review checklist
Concern
Preferred practice
Evidence
ConcernLegality
Preferred practiceOne concern per named block
EvidenceRequirement trace or comment
ConcernPerformance
Preferred practiceBound sizes and reduce redundant rules
EvidenceSolver profile or regression timing
ConcernProbability
Preferred practiceState intended weights and ordering
EvidenceCoverage distribution
ConcernFailure
Preferred practiceCheck return and preserve seed/state