Hello !
Trying a basic array to get with a defined sum value but the results are totally random.
a. Just array.sum == 1000 won’t generate the required random variables ?
b. If not for using the other constraint [arr.sum with (item<(1000/arr.size)) == 1000;], the tool errors out with below error [not sure why its considering the 1’].
constraint arr_sum_c // (from this) (constraint_mode = ON) (rand_array_with_sum.sv:5)
{
((1'(((((((((((arr[0] < (1000 / 10)) + (arr[1] < (1000 / 10))) + (arr[2] < (1000 / 10))) + (arr[3] < (1000 / 10))) + (arr[4] < (1000 / 10))) + (arr[5] < (1000 / 10))) + (arr[6] < (1000 / 10))) + (arr[7] < (1000 / 10))) + (arr[8] < (1000 / 10))) + (arr[9] < (1000 / 10))))) == 1000);
}
module rand_array_with_sum;
class rand_array_with_sum;
rand int unsigned arr[10];
constraint arr_sum_c {
// arr.sum with (item<(1000/arr.size)) == 1000;
arr.sum == 1000;
}
function print_info();
foreach (arr[s]) $display("Ele %0d Val %d", s, arr[s]);
endfunction: print_info
endclass: rand_array_with_sum
initial begin
rand_array_with_sum raws = new();
assert (raws.randomize());
raws.print_info();
end
endmodule: rand_array_with_sum
Please provide your comments !