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

AboutRoadmapCareersInternshipsFAQContactPrivacyTerms
Skip to lesson

Course contents

  • How to Use This Puzzle Bank
  • SystemVerilog Language Puzzles25
  • Difficulty Guide
  • Full Topic Map
  • Interview-Day Tips
  • Study Route: One Week Before the Interview
  • Study Route: Two Weeks
  • Study Route: Four Weeks (Full Course)4
  • OOP & Testbench Puzzles25
  • Concurrency & Timing Puzzles25
  • Randomization & Constraint Puzzles25
    • Constraint Solving Order Puzzles
      • Implication vs Partitioned Branches
      • Bidirectional Solving of x+y==10
      • if-else with Overlap on One Value
      • randc Cycle with a Skipped Value
      • Width Wrap in a Sum Constraint
      • Array Size Coupled to Content
    • Distribution Puzzles (`dist`, `:=` vs `:/`)
    • solve...before Bias Puzzles
    • randomize() with Puzzles
    • Randomization & Constraint Puzzles: Tricky Q&A
  • SVA Assertion Puzzles25
  • Functional Coverage Puzzles25
  • Logic & Aptitude Puzzles25
  • Scenario & Debug Puzzles25
  • UVM Testbench Puzzles25
  • Clock, Reset & CDC Puzzles25
  • Bus and Interface Protocol Puzzles25
  • Interview Prep: Puzzle Rounds7
  • DV Puzzle Cheatsheet
Loading lesson

←Constraint Solving Order Puzzles
  1. Topics
  2. DV Interview Puzzles
  3. Randomization & Constraint Puzzles
  4. Constraint Solving Order Puzzles
  5. randc Cycle with a Skipped Value
On this page

    VLSI DV Interview PuzzlesAll levels

    randc Cycle with a Skipped Value

    randomize() is called six times in a row on the same object. What is guaranteed about the six printed values, and what is the exact probability that call 4 returns the same value as call 3? Assume each randc cycle is a uniformly random permutation of the legal values.

    Puzzle

    Difficulty: Medium · Puzzle 4 of 6 · Topic: Constraint Solving Order Puzzles

    randomize() is called six times in a row on the same object. What is guaranteed about the six printed values, and what is the exact probability that call 4 returns the same value as call 3? Assume each randc cycle is a uniformly random permutation of the legal values.

    Code

    design.sv
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    class rc_cycle;
      randc bit [1:0] r;
      constraint c_skip { r != 2; }
    endclass
    
    rc_cycle o = new();
    repeat (6) begin
      assert(o.randomize());
      $write("%0d ", o.r);
    end

    Hint

    The cycle length is the number of legal values, not 2**width.

    Step-by-step solution

    Diagram
    1) The legal values of r are {0,1,3}, so the randc cycle has length 3, not 4.
    2) Calls 1-3 are one full cycle: each of 0, 1, 3 exactly once, in some order. Calls 4-6 are a second, independent cycle with the same property.
    3) Guaranteed: the value 2 never appears, calls within a cycle never repeat, and over the six calls each of 0, 1, 3 appears exactly twice. The order inside a cycle is not guaranteed.
    4) A repeat can only happen at the cycle boundary: call 4 (first of cycle 2) equals call 3 (last of cycle 1). With two independent uniform permutations of 3 values there are 6*6=36 pairs, and 12 of them have last(cycle1)==first(cycle2), so P=12/36=1/3.
    5) By the same symmetry, P(call 1 == 3)=1/3.

    Answer

    Answer: Cycle length 3: the six values are two permutations of {0,1,3} (each value exactly twice, never 2). P(call 4 == call 3) = 1/3 exactly.

    How this was checked

    Checked by running a model of the rule in a Python model and Verilator 5. Exact enumeration of the constraint set per the LRM (the LRM defines the distribution; simulator solvers need not be uniform). Models each randc cycle as a uniformly random permutation of the legal values {0,1,3}, as the prompt assumes. Compile + run on Verilator: 50 fresh objects, six randomize() calls each; the value 2 never appears and no value repeats inside a three-call cycle (the order inside a cycle is not asserted).

    Why candidates get it wrong

    A common answer is 'r cycles through 0,1,2,3', i.e. a cycle of 4. A hard constraint removes value 2 from the cycle itself, so the length is 3 and 2 never shows. Also 'no back-to-back repeats' is false across the cycle boundary (1/3 chance); only the per-cycle no-repeat is guaranteed. The order inside a cycle is implementation-defined (Verilator 5.048 produced cycles 3 1 0, 3 0 1, 0 3 1, all legal).

    Interviewer follow-up

    What happens to the cycle if the constraint becomes `r inside {1,3};`? Model answer: only two values are legal, so the cycle length is 2 and four consecutive calls give each of 1 and 3 exactly twice; then P(call 3 == call 2)=1/2 under the uniform-permutation assumption (the two cycles are independent, orders 1,3 or 3,1). If constraints change mid-run the legal set is always respected, but where in the cycle you resume is implementation-defined.

    Say it out loud

    The legal values are zero, one and three, so the randc cycle has length three, not four, and two never appears. Calls one to three are each value once in some order, and calls four to six are a second cycle, so each value shows up exactly twice. A repeat can only happen at the cycle boundary, and the chance that call four equals call three is exactly one third. The trap is expecting a cycle of four or believing there are never back-to-back repeats. Next I would check what happens if the constraint changes mid-run, since where the cycle resumes is implementation defined.

    Related topics

    • rand vs randc

    • randc Internals & Limits

    • Back to Constraint Solving Order Puzzles

    • Randomization & Constraint Puzzles section

    Previous

    89 / 293

    Next: Width Wrap in a Sum Constraint

    Up next

    Up nextWidth Wrap in a Sum Constraint

    Sign in to save progress

    Practice this lessonPrevious lessonReport an error

    See also

    • Implication vs Partitioned Branches
    • Bidirectional Solving of x+y==10
    • Array Size Coupled to Content