Randomisation and Constraints

i wanted to have a constraint something like below,

Packets within range say “abc” to “def” & “tuvw” to “xyz”
should be generated once in every 2 packets.

and declared the constraint like below, but i’m not getting the packets correctly can anyone clear this doubt for me?

constraint c2 {!(addr inside {lmn}); addr dist {[abc:def]:/ 2,[tuvw:xyz] :/ 2};}

In reply to Mahantha Deeksha S B:

The constraint you coded is 50% of results in the range abc:def, the other 50% inside the range tuvw:xyz. But to match your description, you would write

constraint c2 {!(addr inside {lmn}); (addr inside {[abc:def],[tuvw:xyz]}) dist {1:=1, 0:=1); }

This says 50% of the time the inside operator evaluates true, the other 50% it is false.

In reply to dave_59:
Thank you sir, got the answer.

In reply to Mahantha Deeksha S B:

Can you share the full code. Any other way we can randomize the string .

In reply to vishalkshetry:
This was the class i had written,
and i don’t know how to write the constraints for string randomisation but you can try with rand sequence,

class packet;
  rand bit [31:0] addr;
  randc int data [];
  rand enum  {idle,busy,write,read,resp} mode;
  rand bit [3:0] xfer_id;
  //-----------------------------------------------
  function new();
    data = new[10];
  endfunction
  //-----------------------------------------------
  constraint c1 {unique{addr};addr[3:0] == 0;unique{xfer_id};};
  constraint c2 {!(addr inside {[32'hf000:32'h1_0000]});(addr inside {['h0000:'h8000],['h1000_0000:'hffff_fff0]}) dist {1:=1, 0:=1};}
  constraint c3 {soft (mode == busy || mode == read) -> (data.size() == 0);soft data.size() <= 300;}
  constraint c4 {soft data.size() > 0;soft data.size() <= 128;}
  constraint c5 {foreach(data[i]) data[i] inside {'h00,'hAA,'hBB,'hCC,'hDD,'h44,'d88,'hFF,'h11,'h22};}
  //-----------------------------------------------
  function void display();
    $display("The properties values  are addr %0d data %0p enum %0s xfer_id %0d", addr, data, mode,xfer_id);
  endfunction
  //-----------------------------------------------
endclass