Dynamic array randomization

Please consider the class code below.

class c;
   rand int arr[];
   constraint C1 {  foreach(arr[i]) {
                        arr[i] < 5;
                        arr[i] > 0;
                    } } 
   constraint C2 { arr.sum() == 14; } 
   //constraint C3 { arr.size < 5; } 
endclass

When I try to randomize it, it fails. I am using IUS, but I tried it VCS from edaplayground.
When I push in C3 constraint, VCS works with it, but IUS does not. Both works if C3 has equality(==) instead of < . Can somebody please explain if LRM prohibits it and what is the work-around for such issues.
Also, if someone has MTI, please see if it works for you. I am passing a small module, in case you don’t want to write your own.

module test;
   c obj = new;
    initial begin
        obj.randomize();
        $display("%p ", obj.arr);
        $finish(2);
    end
endmodule

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

In reply to dave_59:

Thanks Dave,
“You will see that only solutions choosing a size of 4 succeed.”
Even a size of 14, will succeed, isnt it?

I added
constraint C3 { arr.size >= 4; arr.size <= 14; }
and now it seems to work.
Thanks for all your help.

How do we know this? Is it an arcane interpretation of LRM?
“The value for the size of an array gets chosen and becomes a state variable”

In reply to sharatk:

The size of a dynamic array or queue declared as rand or randc can also be constrained. In that case, the array shall be resized according to the size constraint, and then all the array elements shall be randomized

If an array is constrained by both size constraints and iterative constraints, the size constraints are solved first and the iterative constraints next. As a result of this implicit ordering between size constraints and iterative constraints, the size method shall be treated as a state variable within the foreach block of the corresponding array.

In reply to dave_59:

Thanks Dave.