Randomization failed

Hi all,

I am trying to randomize a variable whose values should not be inside some set of values, so I have used ! inside, however i am getting the values within the range. Where am i going wrong?

module top;
  bit[1:0] a;
  initial begin
    repeat(10) begin
      std::randomize(a) with {!a inside {0,2};};
      $display("a is %d",a);
    end
    
  end
endmodule

Edaplayground link: Edit code - EDA Playground

I am getting 2 in the randomization which I am not intended to get.

In reply to kranthi445:

Hi all,
I am trying to randomize a variable whose values should not be inside some set of values, so I have used ! inside, however i am getting the values within the range. Where am i going wrong?

module top;
bit[1:0] a;
initial begin
repeat(10) begin
std::randomize(a) with {!a inside {0,2};};
$display("a is %d",a);
end
end
endmodule

Edaplayground link: Edit code - EDA Playground
I am getting 2 in the randomization which I am not intended to get.

Try

module top;
  bit[1:0] a;
  initial begin
    repeat(10) begin
      std::randomize(a) with {!(a inside {0,2});};
      $display("a is %d",a);
    end
    
  end
endmodule

HTH,
-R