RTL & verification

constrained-random verification

Imagine you have to test a vending machine. You could hand-write a checklist — insert a dollar, press B4, expect a candy bar — but you'd only ever check the handful of cases you thought of. The bugs that bite are the ones nobody pictured: someone jams in three coins, hits two buttons at once, and asks for change all in the same second. Constrained-random verification flips the work around. Instead of scripting each test by hand, you describe the rules of legal input — coins must be valid denominations, a selection must be a real slot — and then let the tool fire thousands of random combinations that all obey those rules, hunting for the corner case no human would think to write down.

More precisely, it is a stimulus-generation strategy where each test case is drawn at random from a space bounded by constraints — declarative rules that keep the random values legal and interesting. A constraint solver picks values that satisfy every rule simultaneously: an address that stays in range, a packet length that's legal for the protocol, a burst type that's allowed only when another field is set. Run with a different random seed each time and a single testbench explores a huge swath of the input space across many runs, reaching states a directed test would never stumble into.

The catch is that randomness alone tells you nothing about what you actually exercised, so the technique never travels alone. You pair it with functional coverage to measure which scenarios actually got hit — and to know when you can stop — and with assertions to automatically flag when the design misbehaves; together these turn a flood of random cases into a measurable, self-checking campaign. This is the engine underneath modern UVM testbenches, where constrained-random generation, coverage, and checking are the standard way large RTL designs get verified.

class bus_txn;
  rand bit [31:0] addr;
  rand bit [7:0]  len;
  constraint legal { addr[1:0] == 2'b00; len inside {[1:64]}; }  // word-aligned, bounded length
endclass

A transaction class whose address and length are randomized, but only within legal bounds set by the constraint — here the address is forced word-aligned and the length kept in range.

"Random" here is a bit of a misnomer — the values are pseudo-random and fully reproducible. Re-running with the same seed replays the exact same stimulus, which is what lets a team reliably reproduce and debug a bug that a random run first uncovered.

Also called
constrained-random testingCRTconstrained random stimulusrandomized verification约束随机验证約束隨機驗證约束随机测试約束隨機測試