How to implement this constraint?

Hi, all

class a;

rand int a[10];
rand int b
rand int index_max;

endclass: a

if I want to implement a constraint that meet the followings at the same time:

  1. 0 < a[i] < 100;
  2. 1 <= index_max <= 10;
  3. the sum of a[0] to a[index_max] equals b;

anyone can give me some advises, thanks

In reply to EnRoute_zt:

foreach (a[ii]) a[ii] inside {[1:99]};
index_max inside {[1:10]};
b == a.sum(item) with (item.index <= index_max ? item : 0);

In reply to dave_59:

thanks, that’s exactly what I want to implement