In reply to ben@SystemVerilog.us:
Ben’s solution doesn’t not take int account that the min and max values need to be seen by aint number of attempts (Prat_0693, it would help to use more descriptive variable names, like count for aint, and max_value for bint).
The easiest thing to do would be to generate the numbers in advance by putting them into a list.
class numbers;
int count=4;
int max_value=10;
rand int list[];
constraint c_range {foreach(list[ii]) list[ii] inside {[0:max_value]};}
function void pre_randomize(); list = new[count]; endfunction
function void post_randomize();
list.sort();
if (list[0] != 0) list[0] = 0;
if (list[count-1] != max_value) list[count-1] = max_value;
list.shuffle();
endfunction
endclass