Randomize dynamic array with constraint array.sum()

Hi,
I try to randomize dynamic array with constraint:

 
  rand int unsigned evgm_data[];
  int evgm_data_size;
  int evgm_data_sum;
  .
  .
  .
  evgm_data_size = 4;
  evgm_data_sum  = 64;                                 

  std::randomize(evgm_data) with{ evgm_data.size() == evgm_data_size;
                                  evgm_data.sum() <= evgm_data_sum; //inside{[0:evgm_data_sum]};
                                };

but the result is:
evgm_data[0] = 659249328
evgm_data[1] = 3730814212
evgm_data[2] = 1522248548
evgm_data[3] = 2677622556

what is the problem?

In reply to Yehu:

There is no problem. You didn’t account for an overflow situation.

An easy fix is to cast your constraint appropriately. Or constrain each element of the array to be less than evgm_data_sum.

In reply to cgales:

Thank you for the answer, can you give me an example what you mean in the first option?

In reply to Yehu:


std::randomize(evgm_data) with{ evgm_data.size() == evgm_data_size;
  evgm_data.sum() with ( 36'(item) ) <= 36'(evgm_data_sum); //inside{[0:evgm_data_sum]};
};

In reply to cgales:

it works
Thank you!

In reply to cgales:

Hi cgales,

Could you please give me the second option?