Skip to content
DenseChip
Learn
PracticeCode labInterview

DenseChip

Navigate

Menu

LearnPracticeCode labInterview

Tools

All toolsSV editorCode repoResume
DenseChip

Practice, courses, and chip-design tools in one focused workspace.

LearnPracticeCode labInterviewToolsLearning paths

© 2026 DenseChip

AboutContactPrivacyTerms
Skip to lesson

Course contents

  • Start Here6
  • SystemVerilog Language Foundations28
  • Object-Oriented SystemVerilog for Verification30
  • Constraint Randomization — Interview-Critical Deep Dive36
    • Randomization Basics: rand, randc & randomize()
    • Constraint Operators & Expressions
    • Dynamic Constraint Control
    • Randomizing Arrays and Queues
      • Constraining Array Size
      • foreach Constraints
      • sum(), Aggregate Constraints
      • unique Constraints
      • Arrays of rand Objects
    • How the Constraint Solver Works
    • Debugging Randomization Failures
    • Interview Drills — Constraints and Randomization Q&A
  • SystemVerilog Assertions — Interview-Critical Deep Dive40
  • Functional Coverage in SystemVerilog22
  • Testbench Architecture in SystemVerilog23
  • Advanced Language & Integration25
  • Senior & Interview Preparation21
  • Principal-Level Verification28
Loading lesson

‹Constraint Randomization — Interview-Critical Deep Dive
  1. Topics
  2. SystemVerilog
  3. Constraint Randomization — Interview-Critical Deep Dive
  4. Randomizing Arrays and Queues

Part 3 · Constraint Randomization · Intermediate

Randomizing Arrays and Queues

Variable-length payloads, ordered lists and transaction streams, described as constraints.

  • 5topics
  • 5lessons

Real stimulus is rarely a handful of scalars. Packets carry variable-length payloads, descriptors form lists, and bursts are streams of related transactions. Each is described as constraints and solved in one randomize() call.

Four kinds of array rule, one solve.

The decision table maps the classic puzzle phrases to their tool. Each row points at the lesson that teaches it.

Puzzle phrase

Tool

Lesson

Ordered / sorted

Guarded foreach neighbour rule

foreach Constraints

Exactly K / at most K

sum() with (int'(condition)) == K

sum(), Aggregate Constraints

All different

unique, pigeonhole checked first

unique Constraints

No two adjacent equal

Guarded i / i-1 relation

foreach Constraints

One-hot / one special

Count == 1, or a rand index

sum(), Aggregate Constraints

Total / budget / checksum

Widened sum() or xor() equation

sum(), Aggregate Constraints

Lesson

Builds

PacketFIFO

Constraining Array Size

Size bounds, the size-first solve order, and the always-bound rule.

None

foreach Constraints

Per-element rules, guarded neighbour relations, and multidimensional iteration.

Payload bytes match len

sum(), Aggregate Constraints

Budgets, checksums, the sum width trap, and the counting idiom.

A correct check byte

unique Constraints

All-distinct arrays, the permutation recipe, and unique versus randc.

None

Arrays of rand Objects

Construct-then-randomize, one call versus a loop, and traffic shaping.

A burst with idle gaps

Verilator 5.048 runs most of this, with gaps the lessons name where they matter: unique only on fixed-size arrays, size() and sum() not together on a dynamic array, and arrays of rand handles ignored. The full list is on What the Open Simulators Run.

Check yourself A packet needs a payload of 4 to 16 printable bytes. Which constraint pieces does the solution need?

A size bound on data.size() and a foreach rule keeping each byte inside [8'h20:8'h7E], both in one randomize() call.

Interview

Array puzzles are common in senior interviews. Most reduce to a size bound, a guarded foreach relation, and one aggregate equation, plus a stated feasibility check.

PreviousNext: Constraining Array Size

Up next

Up nextConstraining Array Size

Sign in to save progress

Practice this lessonReport an error

See also

  • Randomization Basics: rand, randc & randomize()
  • Constraint Operators & Expressions
  • Dynamic Constraint Control