10 SystemVerilog Constraint Interview Questions with Code
Constraint-writing questions are very common in DV interviews. Each answer shows the constraint code and the trap to avoid.
Updated 05 November 2026 · Written by Semicon Weekly in our own words · 10 questions
Practise these 10 questions free : type, speak or pick from 4 options and get an instant AI score.
Start practising →
Questions on this page Write a constraint for a dynamic array of size 6 to 10 with unique even values between 16 and 127. Write a constraint to generate unique array elements without using unique. Constrain a 32-bit variable so that exactly one bit is high (one-hot). Generate a value between 34 and 43 without using inside. How do you generate random real numbers between 1.35 and 2.68? Write a constraint to fill an array with the pattern 0 1 0 2 0 3 0 4 ... Array of size 10: first five ascending, last five descending, all multiples of 5. Write a constraint that generates prime numbers between 1 and 100. How can you override an existing constraint? Write a constraint for int arr[2][4] so every element is even and less than 50.
medium Arrays code
1. Write a constraint for a dynamic array of size 6 to 10 with unique even values between 16 and 127.Show answer arr.size() inside {[6:10]}; foreach (arr[i]) { arr[i] inside {[16:127]}; arr[i] % 2 == 0; } unique {arr}; (or nested foreach with i != j check if unique not allowed)
Common mistake: Forgetting to constrain size
Interviewer may ask next: Do it without the unique keyword.
Answer this in the AI interview bot → medium Patterns code
2. Write a constraint to generate unique array elements without using unique.Show answer foreach (a[i]) foreach (a[j]) if (i != j) a[i] != a[j];
Answer this in the AI interview bot → medium Bits code
3. Constrain a 32-bit variable so that exactly one bit is high (one-hot).Show answer $countones(x) == 1; or x != 0 && (x & (x - 1)) == 0
Interviewer may ask next: Now exactly 12 bits high, none adjacent.
Answer this in the AI interview bot → easy Range code
4. Generate a value between 34 and 43 without using inside.Show answer x >= 34; x <= 43;
Answer this in the AI interview bot → medium Real code
5. How do you generate random real numbers between 1.35 and 2.68?Show answer rand real is not supported by many tools; randomize an int scaled value, e.g. rand int v; v inside {[135:268]}; then real r = v / 100.0 in post_randomize
Common mistake: Declaring rand real and assuming it works everywhere
Answer this in the AI interview bot → medium Patterns code
6. Write a constraint to fill an array with the pattern 0 1 0 2 0 3 0 4 ...Show answer foreach (a[i]) if (i % 2 == 0) a[i] == 0; else a[i] == (i + 1) / 2;
Answer this in the AI interview bot → medium Patterns code
7. Array of size 10: first five ascending, last five descending, all multiples of 5.Show answer foreach (a[i]) { a[i] % 5 == 0; if (i > 0 && i < 5) a[i] > a[i-1]; if (i > 5) a[i] < a[i-1]; }
Common mistake: Off-by-one in the index conditions
Answer this in the AI interview bot → hard Math code
8. Write a constraint that generates prime numbers between 1 and 100.Show answer Build a list of primes (2..97) in pre_randomize or a helper function, then constrain x inside {primes}; a function called inside a constraint is evaluated before solving, so it cannot search divisors of the value being solved
Answer this in the AI interview bot → medium Override theory
9. How can you override an existing constraint?Show answer Extend the class and redefine a constraint with the SAME name (replaces it); add a new constraint in the child (adds to it); inline randomize() with {} (adds); turn off with constraint_mode(0); conflicts make randomize() fail and return 0
Answer this in the AI interview bot → medium Arrays code
10. Write a constraint for int arr[2][4] so every element is even and less than 50.Show answer foreach (arr[i, j]) { arr[i][j] % 2 == 0; arr[i][j] < 50; arr[i][j] >= 0; }
Common mistake: Forgetting the lower bound for signed int (negatives appear)
Answer this in the AI interview bot →