Skip to question
asic.fyi
DesignVerificationSystemVerilogFirmwareArchitectureInterviews
asic.fyi/Interview questions/Constrain exactly one duplicated nonadjacent pair

Hardware interview practice

Constrain exactly one duplicated nonadjacent pair

HardConstraintsSystemVerilog

Constrain ten integers so exactly one value occurs twice, the duplicate positions are nonadjacent, and every other value occurs once.

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 int a[10];
rand int p, q;
Reviewed example

Work through one case

Input
a = {7,1,2,7,3,4,5,6,8,9}, p = 0, q = 3
Expected output
legal: exactly one repeated value (7) at nonadjacent positions 0 and 3

Only value 7 repeats, its positions differ by three, and all remaining values are pairwise distinct.

What to cover

Requirements

  1. Constrain 0 <= p < q < 10 and q - p > 1.
  2. Require a[p] == a[q].
  3. Require every other index pair to differ.
  4. Bound all ten values to the inclusive range 0 through 99.
asic.fyi · Learn silicon end to end.info@asic.fyi