Skip to question
asic.fyi
DesignVerificationSystemVerilogFirmwareArchitectureInterviews
asic.fyi/Interview questions/Constrain one triplicate and seven singletons

Hardware interview practice

Constrain one triplicate and seven singletons

MediumSystemVerilog ConstraintsSystemVerilog

Randomize ten integers in 0..31 so one selected value occurs exactly three times 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 unsigned arr[10];
rand int unsigned repeated;
Reviewed example

Work through one case

Input
repeated=4, arr='{4,9,4,1,6,11,4,2,8,10}
Expected output
Legal randomization result

Four appears exactly three times and all seven remaining values are unique.

What to cover

Requirements

  1. Restrict all values and repeated to 0..31.
  2. Make exactly three positions equal repeated.
  3. Make the other seven values pairwise distinct and different from repeated.
  4. Allow the three repeated positions to appear anywhere.
Continue practicing

Related questions

SystemVerilog ConstraintsConstrain five non-overlapping address windows→ConstraintsConstrain three disjoint child arrays→ConstraintsConstrain a DMA transfer to one 4KB page→
asic.fyi · Learn silicon end to end.info@asic.fyi