Coverges implicit bins

class transaction ;
  randc bit[3:0] addr;
  randc bit[3:0] data;
  
  covergroup cg;
   coverpoint addr;
   coverpoint data;
  endgroup
  function new();
  cg=new();
  endfunction
endclass

module tb();
  transaction tr;
  initial
    begin
      tr=new();
      repeat(16)
        begin
      tr.cg.sample();
      tr.randomize();
     
      $display("the values of addr=%0d,data=%0d",tr.addr,tr.data);
    end
    end
endmodule

In the above code i taken the addr,data [3:0] range is 0-15, i randomize with rand c for 16 time a the bins are coverd but i did not get 100% coverage (but when i randomize more than 16 times iam geting 100% coveraage.

In reply to Prudhvi Krishna:

You call sample() before randomize(). In the first iteration, the values are ‘x’, so there is no valid sample. You should call randomize() and then sample().

Also, you should always validate that randomize() was successful by checking the return code.


class transaction ;
  randc bit[3:0] addr;
  randc bit[3:0] data;

  covergroup cg;
    coverpoint addr;
    coverpoint data;
  endgroup

  function new();
    cg=new();
  endfunction
endclass

module tb();
  transaction tr;

  initial begin
    tr=new();
    repeat(16) begin
      if (!tr.randomize) $display("Randomize call failed");
      else begin
        tr.cg.sample();
        $display("the values of addr=%0d,data=%0d",tr.addr,tr.data);
      end
    end
  end
endmodule