Skip to question
asic.fyi
DesignVerificationSystemVerilogFirmwareArchitectureInterviews
asic.fyi/Interview questions/Random palindrome array constraint

Hardware interview practice

Random palindrome array constraint

MediumSystemVerilog ConstraintsSystemVerilog

A sequence item needs a short digit array that reads the same forward and backward. Write constraints for size, digit range, full palindrome symmetry, and a bounded sum.

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

class palindrome_item;
  rand int unsigned digits[];
endclass
Reviewed example

Work through one case

Input
digits='{4,0,1,1,0,4}
Expected output
Legal; size=6 and sum=10

Every element equals its mirror, every digit is 0..9, and the total is within 36.

What to cover

Requirements

  1. Constrain digits.size() to be from 5 through 9 inclusive.
  2. Constrain every element to the inclusive range 0 through 9.
  3. For every valid index i, constrain digits[i] to equal digits[digits.size()-1-i].
  4. Constrain the sum of all digits to be no greater than 36.
Continue practicing

Related questions

SystemVerilog Data StructuresChoose containers from testbench access patterns→
asic.fyi · Learn silicon end to end.info@asic.fyi