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