In the below example if the “addr” is declared as bit[8:0] the randomization is giving incorrect results. However, if “addr” is declared as bit[31:0] correct output is coming. Can somebody please help me to understand why is this happening?
// Incorrect output code
class abc;
rand bit[8:0] addr[];// declared as 9 bits
constraint addr_c{
addr.size == 20;
foreach(addr[i]){
if(i>0) addr[i] > addr[i-1];
addr[i] <300;}
addr.sum == 'h12c;
}
function void post_randomize();
$display("arr = %0p",addr);
endfunction: post_randomize
endclass: abc
//=======================================================
//=======================================================
// Correct results
class abc;
rand bit[31:0] addr[];// declared as 32 bits
constraint addr_c{
addr.size == 20;
foreach(addr[i]){
if(i>0) addr[i] > addr[i-1];
addr[i] <300;}
addr.sum == 'h12c;
}
function void post_randomize();
$display("arr = %0p",addr);
endfunction: post_randomize
endclass: abc