Dynamic array randomization

In reply to sharatk:

Your C2 constraint fails because there are no elements in the
arr
array to produce a sum equaling 14. You need an active constraint on the size of an array for a call to
randomize()
to change the size of a dynamic array.

The value for the size of an array gets chosen and becomes a state variable before constructing the array and evaluating constraints on any elements. If you run your simulations with different seeds, or add a repeat loop, you will see that only solutions choosing a size of 4 succeed. It’s a matter of chance which simulators choose a solution that passes on the first try.

So for this example, you probably want to add another constraint for the minimum array size.

arr.size * 4 >=14