Skip to question
asic.fyi
DesignVerificationSystemVerilogFirmwareArchitectureInterviews
asic.fyi/Interview questions/Constrain a Gray-adjacent sequence

Hardware interview practice

Constrain a Gray-adjacent sequence

MediumConstraintsSystemVerilog

Randomize 16 unique 4-bit values starting at zero so each adjacent pair differs in exactly one bit.

Try it in the question bankReason first. Then compare.

Keep this exact question selected while you check your answer and review the full solution.

Practice this question →
Reviewed example

Work through one case

Input
randomize 16 unique 4-bit values with values[0]=4'b0000
Expected output
One valid result: [0000,0001,0011,0010,0110,0111,0101,0100,1100,1101,1111,1110,1010,1011,1001,1000]

This complete Gray path visits every 4-bit value once and each constrained adjacent pair has Hamming distance one; the last-to-first transition is not constrained.

What to cover

Requirements

  1. Fix the first value at 4'b0000.
  2. Require a Hamming distance of one between neighbors.
  3. Use every 4-bit value at most once.
Continue practicing

Related questions

Clock Domain CrossingImplement asynchronous FIFO full and empty logic→Clock Domain CrossingBinary-to-Gray converter→
asic.fyi · Learn silicon end to end.info@asic.fyi