SV Constraint Error Resolution

I have written a code in which I need an array having numbers between 2 to 5 and the total sum of the array should be 100. I am getting the below error:

*Solver failed when solving following set of constraints

constraint c1 // (from this) (constraint_mode = ON) (testbench.sv:7)
{
(0 == 100);
}*

Below is the code:

class random_const_1 ;
  
  rand int stream_0s_1s [];
  constraint c0 { foreach (stream_0s_1s[i]) stream_0s_1s[i] inside {[2:5]};};
  constraint c1 { stream_0s_1s.sum() == 100 ;};
  
  function void post_randomize();
    foreach (stream_0s_1s[i])
      $display("Post Randomized Array : %d\n",stream_0s_1s[i]);
  endfunction
endclass

module test;
  random_const_1 t1;
  initial
    begin
      t1 = new();
      t1.randomize();
    end
endmodule

Can someone point out the error in the code?

In reply to arpitg:

Your array is dynamic and I don’t see it’s size anywhere!
Sorry if I’m wrong :(

In reply to Shashank Gurijala:

The constraints are written in such a way that the size can be different everytime the array is randomized. So, that reason should not be throwing the error. Need more inputs.

In reply to arpitg:

The previous reply was correct.

From section 18.4 of the LRM:
If a dynamic array’s size is not constrained, then the array shall not be resized and all the array
elements shall be randomized.

In this case, the array is of size 0, and since the size isn’t constrained, it remains 0 and you get no elements in the array.

In reply to cgales:

So how do I get away from this problem? Basically I need an array having element values between 2 to 5 (including both) and the total sum of that array has to be equal to 100.

In reply to arpitg:

Add a constraint for the array size. If you have all 5s, the array size would be 20. If you have all 2s, the array size would be 50.


class random_const_1 ;
 
  rand int stream_0s_1s [];
  constraint c0 { foreach (stream_0s_1s[i]) stream_0s_1s[i] inside {[2:5]};};
  constraint c1 { stream_0s_1s.sum() == 100 ;};
  constraint c2 { stream_0s_1s.size() inside {[20:50]};};
 
  function void post_randomize();
    foreach (stream_0s_1s[i])
      $display("Post Randomized Array : %d\n",stream_0s_1s[i]);
  endfunction
endclass
 
module test;
  random_const_1 t1;
  initial
    begin
      t1 = new();
      t1.randomize();
    end
endmodule

In reply to arpitg:

Try constraining the size of the array, say, array.size > 19 and array.size < 51 (if all elements are 2, min size needed is 50 and if all the elements are 5 the min size is 20)