Write a constraint for a 10 bit variable en so that; → 10% of the time 1 bit in en is high → 10% of the time 2 bits in en are high … → 10% of the time all 10 bits in en are high.
class sample;
rand bit [10:1] en;
constraint x{
foreach(en[i])
{
$countones(en) == i dist {1:=10,0:=90};
}
}
endclass
constraint x {$countones(en) dist {1:=10, 2:=10, 10:=10}; } ;
endclass
module top;
import uvm_pkg::*;
`include “uvm_macros.svh”
sample sc;
initial begin
sc = new();
for (int i = 0; i < 20; i++) begin //sc.i = i;
sc.randomize();
`uvm_info(“TOP”, $sformatf(“en = %b”,sc.en), UVM_MEDIUM)
// sc.i++;
end
end