Skip to question
asic.fyi
DesignVerificationSystemVerilogFirmwareArchitectureInterviews
asic.fyi/Interview questions/Do not repeat the previous five values

Hardware interview practice

Do not repeat the previous five values

MediumConstraintsSystemVerilog

Randomize a four-bit value that differs from each of its five most recent successful values, then maintain that bounded history correctly.

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 →
Starting point

Question code

rand bit [3:0] value;
bit [3:0] history[$];
Reviewed example

Work through one case

Input
history = {1, 2, 3, 4, 5}; randomize produces 9
Expected output
value = 9; new history = {9, 1, 2, 3, 4}

Values 1 through 5 are excluded during the solve, then post_randomize inserts 9 and removes the oldest entry.

What to cover

Requirements

  1. Exclude every value currently stored in the history queue.
  2. Update history only after a successful solve.
  3. Keep at most five prior values, newest first.
  4. Check randomize() failure explicitly at the call site.
Continue practicing

Related questions

ConstraintsPartition a randomized parent array→
asic.fyi · Learn silicon end to end.info@asic.fyi