How to get a non-duplicate randomized value from coverage?

Dear All,

Currently I’m learning the coverage. It’s very powerful methods for verification I think.
But I’v got a problem that I’m trying to get a non-duplicated randomized value .

Here is the code.



class packet;

  rand bit[4:0] img_index;
  rand bit[31:0] crop_seed;

  constraint  const_img_index
  {
    (img_index >= 0 && img_index <= 4);javascript:void(0)
    img_index dist {[0:4] :/ 1};
  }
  constraint  const_crop_seed
  {
    crop_seed dist {[0:4] :/ 1};
  }
  
  
  covergroup img_src;

 img_idx : coverpoint img_index {

   bins b_0 = {32'h0};
   bins b_1 = {32'h1};
   bins b_2 = {32'h2};
   bins b_3 = {32'h3};
	}

 crop_seed : coverpoint crop_seed {

   bins b_0 = {32'h0};
   bins b_1 = {32'h1};
   bins b_2 = {32'h2};
   bins b_3 = {32'h3};
	}

CROSS: cross img_idx, crop_seed;


endgroup

  
endclass




module constr_dist;

  
  initial begin
    packet pkt;
    pkt = new();
    $display("------------------------------------");
        foreach(pkt.img_index[i]) begin
      pkt.randomize();
        $display("\const_img_index = %0d",pkt.img_index);
    end
    $display("------------------------------------");
    $display("------------------------------------");

  end
  
  
endmodule

I got the duplicated randomized value from the codes the below.


------------------------------------
const_img_index = 1
const_img_index = 1
const_img_index = 0
const_img_index = 0
const_img_index = 0
------------------------------------
------------------------------------

  1. How to get non-duplicate randomized values? I expected that
    const_img_index has 5 values from 0 to 4. but the same value come out.

  2. If all bins don’t hit, I want to keep running randomize until all bins hits. Is there any possible way to get this method?

SIM: coverage distribute(1) - EDA Playground

In reply to UVM_LOVE:

Randomizing only 5 times does not give a representative distribution. If you randomize more, you will see the results you expect:


module constr_dist;
  initial begin
    packet pkt;
    pkt = new();
    $display("------------------------------------");
    repeat (50) begin
      if (!pkt.randomize()) $display("Randomization error");
      else $display("const_img_index = %0d",pkt.img_index);
    end
    $display("------------------------------------");
    $display("------------------------------------");
  end
endmodule

Also, you don’t instantiate your covergroup anywhere, nor sample it, so you aren’t generating any coverage metrics.

In reply to UVM_LOVE:



...
...
...
CROSS: cross img_idx, crop_seed;

endgroup
  
  function new();
       img_src = new();
    endfunction
endclass
 
module constr_dist;

  initial begin
    packet pkt;
    pkt = new();
    
    $display("------------------------------------");
   
    while(pkt.img_src.img_idx.get_inst_coverage() != 100) begin
    //while(pkt.img_src.get_inst_coverage() != 100) begin
      pkt.randomize();
      pkt.img_src.sample();
      $display("\const_img_index = %0d",pkt.img_index);
    end
    
    $display("------------------------------------");
 
  end
 
 
endmodule

In reply to Hiren Solanki:

In reply to UVM_LOVE:


...
...
...
CROSS: cross img_idx, crop_seed;
endgroup
function new();
img_src = new();
endfunction
endclass
module constr_dist;
initial begin
packet pkt;
pkt = new();
$display("------------------------------------");
while(pkt.img_src.img_idx.get_inst_coverage() != 100) begin
//while(pkt.img_src.get_inst_coverage() != 100) begin
pkt.randomize();
pkt.img_src.sample();
$display("\const_img_index = %0d",pkt.img_index);
end
$display("------------------------------------");
end
endmodule

Would you please let me know any special reason you used get_inst_coverage instead of using get_coverage ?

In reply to UVM_LOVE:

get_inst_coverage works the same as get_coverage if the per_instance option is zero or there is just one instance of that covergroup.

In reply to UVM_LOVE:

Dear All,
Currently I’m learning the coverage. It’s very powerful methods for verification I think.
But I’v got a problem that I’m trying to get a non-duplicated randomized value .
Here is the code.


class packet;
rand bit[4:0] img_index;
rand bit[31:0] crop_seed;
constraint  const_img_index
{
(img_index >= 0 && img_index <= 4);javascript:void(0)
img_index dist {[0:4] :/ 1};
}
constraint  const_crop_seed
{
crop_seed dist {[0:4] :/ 1};
}
covergroup img_src;
img_idx : coverpoint img_index {
bins b_0 = {32'h0};
bins b_1 = {32'h1};
bins b_2 = {32'h2};
bins b_3 = {32'h3};
}
crop_seed : coverpoint crop_seed {
bins b_0 = {32'h0};
bins b_1 = {32'h1};
bins b_2 = {32'h2};
bins b_3 = {32'h3};
}
CROSS: cross img_idx, crop_seed;
endgroup
endclass
module constr_dist;
initial begin
packet pkt;
pkt = new();
$display("------------------------------------");
foreach(pkt.img_index[i]) begin
pkt.randomize();
$display("\const_img_index = %0d",pkt.img_index);
end
$display("------------------------------------");
$display("------------------------------------");
end
endmodule

I got the duplicated randomized value from the codes the below.


------------------------------------
const_img_index = 1
const_img_index = 1
const_img_index = 0
const_img_index = 0
const_img_index = 0
------------------------------------
------------------------------------

  1. How to get non-duplicate randomized values? I expected that
    const_img_index has 5 values from 0 to 4. but the same value come out.
  2. If all bins don’t hit, I want to keep running randomize until all bins hits. Is there any possible way to get this method?
    SIM: coverage distribute(1) - EDA Playground

You can also change rand to randc (cyclic rand) which won’t repeat the duplicate values.
Also we have to remove the dist usage if we switch to randc and your constraint should look like this. I tried it in eda playground by copying your code and making the edits mentioned and it works as expected.

randc bit[4:0] img_index;
constraint const_img_index
{
(img_index >= 0 && img_index <= 4);
}