Part 3 · Constraint Randomization · Intermediate

Debugging Randomization Failures

Hub — failure taxonomy, contradiction hunting, distribution debugging, seed reproducibility, silent failures, and the interview-ready debug checklist.

Overview

When randomize() misbehaves, there are exactly two symptoms — it returns 0, or it returns 1 with values you did not want — but many root causes. The difference between a junior and a senior verification engineer is a systematic triage process instead of staring at constraints hoping the bug jumps out. This topic builds that process: classify the failure, isolate the contradiction or skew, reproduce it deterministically, and harden the testbench so the same class of failure cannot hide again.

This material is interview-critical. “Your randomize() call fails — walk me through what you do” is one of the most common senior-level verification interview questions, because the answer reveals whether you understand solver semantics (bidirectional solving, implication, soft constraints, randc, random stability) or have only memorized syntax. Every sub-lesson here ends with the interview angle spelled out.

Sub-topics

  1. Randomization Failure Taxonomy — the four failure modes and the triage flowchart.

  2. Finding Contradictions — binary search with constraint_mode(0), randomize(null), minimal repros.

  3. Wrong Distribution Debugging — histograms, covergroups on rand fields, implication skew.

  4. Reproducing Random Failures — seed capture/replay, random stability, srandom isolation.

  5. Silent Failures & Defensive Idioms — null handles, rand_mode leftovers, randomize_or_fatal.

  6. The Randomization Debug Checklist — the consolidated interview-ready answer plus a full worked session.

diagram
RANDOMIZATION DEBUG TOPIC MAP

  symptom observed
       |
       +-- randomize() returns 0 ------------+
       |                                     |
       |                              [Failure Taxonomy]
       |                                     |
       |                          [Finding Contradictions]
       |                                     |
       |                       binary search constraint_mode(0)
       |                       randomize(null) consistency check
       |                       minimal repro -> fix
       |
       +-- returns 1, values look wrong -----+
       |                                     |
       |                       [Wrong Distribution Debugging]
       |                       histogram in post_randomize
       |                       covergroup on rand fields
       |
       +-- values never change / field skipped
       |                                     |
       |                       [Silent Failures]
       |                       null handle? rand_mode off? randc state?
       |
       +-- fails only sometimes, only some seeds
                                             |
                       [Reproducing Random Failures]
                       capture seed -> replay -> then debug

  All paths feed -> [The Debug Checklist] (interview answer)

Key takeaways

  • Two symptoms, four failure modes: hard contradiction, silent skip, wrong distribution, irreproducibility.

  • Always check the randomize() return value — assert(randomize()) or a fatal wrapper, never a bare call.

  • Debug flow: classify, isolate (constraint_mode binary search), reproduce (seed), harden (defensive idioms).

  • Interviewers ask this to probe solver-semantics understanding, not syntax recall.