In the below posted code why i am not get the value os awsize as 0 or 1 ? i want awsize to be 0,1 and 2

class amba3_axi_packet #(ADDR_BITS = 32, DATA_BITS = 32, TXID_BITS = 4, STRB_BITS = DATA_BITS / 8);
  rand logic [          2:0] awsize;
  rand logic [ADDR_BITS-1:0] awaddr;
  rand logic [STRB_BITS-1:0] wstrb[$];
       logic [STRB_BITS-1:0] wstrb_m;

  constraint aw_size{ awsize inside {0,1,2};}

  constraint w_strobe_2{ if(awsize == 2)
  			foreach(wstrb[i])
			wstrb[i] == 'hf;}
  constraint w_strobe_0{ if(awsize == 0 )
		      	 wstrb_m == 2**(awaddr % (DATA_BITS/8) );}

     constraint w_strobe_1{ if(awsize == 1) 
                        if(awaddr % (DATA_BITS/8) == 0 || awaddr % DATA_BITS/8 == 1)
					wstrb_m == 3;
    					else
					wstrb_m == 12;}
function void post_randomize;
if(awsize == 0 ) begin
wstrb[0] = wstrb_m;
for(int i=1;i<wstrb.size();i++) begin
wstrb[i] = wstrb[i-1] <<< 1;
if(wstrb[i-1] == 8)
wstrb[i] = 1;
 end
 end
if(awsize == 1 ) begin
  if(awaddr % (DATA_BITS/8) == 0 || awaddr % (DATA_BITS/8) == 1) begin
	  wstrb[0] = wstrb_m;
  for(int i=1;i<wstrb.size();i++)
  wstrb[i] = ~wstrb[i-1]; 
end
 if(awaddr % (DATA_BITS/8) == 2 || awaddr % (DATA_BITS/8) == 3) begin
	
  wstrb[2] = wstrb_m;
  for(int i=1;i<wstrb.size();i++)
 wstrb[i] = ~wstrb[i-1];
end
end

endfunction
function void disp();
  $display("\t|  awsize   |  \t\t%0h ",awsize);
endfunction
                        
endclass
                        
module ex;
amba3_axi_packet pkt;
initial begin
pkt = new();
  repeat(200) begin
pkt.randomize();
pkt.disp();
end
end
endmodule

the output i am getting is

        |  awsize   |  		2 
	|  awsize   |  		2 
	|  awsize   |  		2 
	|  awsize   |  		2 
	|  awsize   |  		2 
	|  awsize   |  		2 
	|  awsize   |  		2

and so on…

In reply to swapnilsrf9:
There are a couple of problem here. First is you declared wstrb_m without a rand qualifier. That leaves it as a state variable with the value 'x and should have been been reported as an error. You are not allowed a 'x or 'z value in a constraint. But even ignore that restriction and assume the initial value is 0, you didn’t use the rand qualifier so only the first two constraints can be meet by choosing 2 for the value of awsize.

If you add the rand qualifier, then another problem pops up in your post_randomize() function. You try to set wstrb[2] when it doesn’t exist.

BTW, please use code tags to format your code. I have done that for you in your post. It would also help to properly indent your code.

In reply to dave_59:

thank you sir…