Skip to Solver fundamentals questions

Part 1 · Solver fundamentals

Understand what the constraint solver promises, define legal domains, and shape probability without confusing membership, weighting, and overrides.

Question directory

Questions for Solver fundamentals

Open an authored answer, then use the surrounding visual and code example to test the rule.

  1. Randomization contractWhat is the difference between rand and randc?SystemVerilog constraints
  2. Randomization contractHow do object.randomize(), std::randomize(), and $urandom_range() differ?SystemVerilog constraints
  3. Randomization contractWhat happens before, during, and after a randomize() call?SystemVerilog constraints
  4. Domains and distributionsHow do you express ranges, sets, and exclusions with inside?SystemVerilog constraints
  5. Domains and distributionsWhat is the difference between := and :/ in a dist constraint?SystemVerilog constraints
  6. Domains and distributionsHow do soft constraints, inline constraints, constraint_mode(), and rand_mode() interact?SystemVerilog constraints
  7. Randomization contractWhen should you use $urandom(), $urandom_range(), $random, or a $dist_* function?SystemVerilog constraints
  8. Randomization contractHow is randcase different from a dist constraint?SystemVerilog constraints
  9. Randomization contractWhat changes when you call randomize(var1, var2) instead of randomize()?SystemVerilog constraints

SystemVerilog Randomization contractKnow what the solver promises.

Separate object randomization from procedural randomness, choose rand or randc deliberately, and treat the Boolean result as part of the transaction contract.

Concept model

Randomization is a legal-solution pipeline

01Build the model
  • Fixed statecurrent object values
  • Unknownsactive rand variables
  • Ruleshard + compatible soft
02Intersect every rule
legalblockedsampled
03Return the contract
At least one legal pointrandomize() == 1

One complete assignment is committed.

Empty intersectionrandomize() == 0

No new values should be assumed.

One solve, one shared model.Written order does not turn the constraints into procedural assignments.

Fixed object state and active random variables enter one declarative model. A successful solve assigns one legal point; an empty intersection returns failure.

Strong answer

rand samples a legal value on each successful randomization and may repeat immediately. randc keeps cyclic state so successive calls on the same object visit each value in its legal domain before repeating.

Reason it through

  • Use rand for normal constrained-random stimulus. A repeated value is legal and is not evidence that randomization failed.
  • Use randc for a small, stable scalar or enum domain when no-repeat traversal is itself the requirement.
  • A new object starts a new randc cycle. Tight or changing constraints can exhaust the remaining cyclic choices and make a later solve fail.
rand and randc comparison
ChoiceAcross callsBest useMain risk
randLegal values may repeatGeneral stimulusAssuming every value appears quickly
randcNo repeat within its cycleSmall IDs or enum sweepsState, cost, and constraint exhaustion

SystemVerilog Domains and distributionsShape the legal value space.

Use inside to define legality, dist to bias sampling, and soft defaults or runtime modes to layer scenario intent without hiding conflicts.

Concept model

Legality and probability are different controls

LegalitySelect the allowed set
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
value inside {[2:7], 12}

Membership removes illegal values. It does not assign probability weights to the remaining values.

Probability weightRead the distribution operator
[0:3] := 4

Full weight per value. The range contributes four weighted entries.

[0:3] :/ 4

Weight shared by the range. The total is divided across its values.

Membership chooses which values remain legal. Distribution operators then assign relative weight, with different range semantics for := and :/.