Code to generate pulses at a given rate using constraint randomization


class pulse
rand bit[3:0]rate;
bit clk;
constraint p_dist{ rate dist{[3:0]:/clk};}
always #5 clk = ~clk;

pulse p;

initial begin
p = new();
assert(p.randomise());
transmit(p);
end
endclass

I have tried distributing constraints using weighted distribution.