Randomization & Constraint - Sum equals to 9

Problem Description

Write constraints with below requirements :

1. Each val[i] is between 1 and 10 (inclusive)

2. Each val[i] is odd

3. The array is strictly ascending (each value greater than the one before)

4. The sum of all three values equals 9

Example:

After randomize() — Run 1:

val = {1, 3, 5}

After randomize() — Run 2:

val = {1, 3, 5}

After randomize() — Run 3:

val = {1, 3, 5} ← always the same

Why? Because only one combination of three odd numbers

between 1–10, in ascending order, adds up to 9.

The solver has no other valid option.

Invalid (must never happen):

val = {1, 3, 7} ❌ sum is 11, not 9

val = {2, 3, 4} ❌ not all odd

val = {5, 3, 1} ❌ not ascending

val = {1, 1, 7} ❌ not strictly ascending

SystemVerilog

Code Editor Access

Log in to write, run and submit your solution to this interview question. It's free.

Output

Output goes here...