Array sum method with functions in constraints

Trying to make an array element total as 300 without using array sum method using functions. After 4 runs it fails.
Not sure what’s wrong or how to decide order when functions are used.

Looks like, random variable are picking 1st before calling user function. Is this means that user functions can not be used for such cases?

link:

p.s. I would like to use functions.

module sample_constraints;
  
class random_value;
    rand int num[2];
    rand int length;
      
    constraint num_c{
      
      foreach(num[i]){
        num[i] inside {[0:length]};
      }
        
    }
    
    constraint length_val_c{
      length == 150;
    }    
    constraint sum_val_c{
      solve length before num;
    }
    
    constraint order_c{
      check_sum(num) == length;
    }
    
        
     function int check_sum(int num_[2]);
         
      foreach(num_[i])begin
        check_sum += num_[i];  
      end
            
    endfunction
  endclass 
  
  random_value s1;
    
  initial begin
    s1 = new();
    repeat(5)begin
      s1.randomize();
      $display( " s1  = %0p", s1);
    end
  end
   
endmodule

s1 = ‘{num:’{110, 40}, length:150}
s1 = ‘{num:’{49, 101}, length:150}
s1 = ‘{num:’{112, 38}, length:150}
s1 = ‘{num:’{36, 114}, length:150}
s1.randomize();
|
xmsim: *W,SVRNDF (./testbench.sv,46|17): The randomize method call failed. The unique id of the failed randomize call is 4.
Observed simulation time : 0 FS + 0
xmsim: *W,RNDOCS: These constraints contribute to the set of conflicting constraints:

  check_sum(num) == length; (./testbench.sv,27)

In reply to Geet:

https://verificationacademy.com/forums/systemverilog/functions-constraints-1#reply-88738