Difference in overflow while using byte and int

In reply to Chandra Shekar N:




class array;
rand byte unsigned arr[];
constraint c_arr{
   arr.size() == 5;
   arr.sum() == 60; //inside {[1:1000]}; // if you want a positive result
   //foreach(arr[i]) arr[i] inside {[0:500]};
}
endclass
 
module tb;
array a=new();
int sum;
initial
repeat(10)
begin
a.randomize();
sum=0;
foreach(a.arr[i])
sum=sum+a.arr[i];
$display("sum =%0d elements of the array to sum up to <1000 ---->>  %0p",sum,a.arr);
end
endmodule


///OUTPUT
# KERNEL: sum =572 elements of the array to sum up to <1000 ---->>  '{237, 35, 97, 196, 7}
# KERNEL: sum =572 elements of the array to sum up to <1000 ---->>  '{115, 149, 160, 144, 4}
# KERNEL: sum =572 elements of the array to sum up to <1000 ---->>  '{141, 250, 16, 155, 10}
# KERNEL: sum =828 elements of the array to sum up to <1000 ---->>  '{129, 245, 119, 113, 222}
# KERNEL: sum =572 elements of the array to sum up to <1000 ---->>  '{182, 74, 28, 157, 131}
# KERNEL: sum =316 elements of the array to sum up to <1000 ---->>  '{93, 134, 30, 14, 45}
# KERNEL: sum =828 elements of the array to sum up to <1000 ---->>  '{213, 183, 237, 10, 185}
# KERNEL: sum =828 elements of the array to sum up to <1000 ---->>  '{239, 73, 114, 213, 189}
# KERNEL: sum =828 elements of the array to sum up to <1000 ---->>  '{18, 111, 224, 254, 221}
# KERNEL: sum =572 elements of the array to sum up to <1000 ---->>  '{142, 147, 67, 166, 50}