Foreach usage in randomization constraints

In reply to peterjin:

I believe the article was showing pseudo-code as a concept. You cannot use a dist constraint without a fixed list of values. There are other ways of constructing random distributions. One way is to select a random number to use in a series of implications where only one can be selected:

class A;
   rand int value;
 
   int a[5] = '{1, 11, 21, 31, 41};
   int b[5] = '{10, 20, 30, 40, 50};
   int c[5] = '{30, 15, 10, 15, 30};
   int d[6] = {0, 30, 45, 55, 70, 100}; // could be computed from c
   rand int range;
   constraint c_range {range inside {[d[$low(d)]:d[$high(d)]-1]};
      solve range before value; } // prevents c_value from skewing distribution
   constraint c_value {foreach (a[ii])
		       range inside {[d[ii]:d[ii+1]-1]} ->
		                        value inside {[a[ii]:b[ii]]};}
endclass