Implementing dist as a function

How will you implement a dist function?
for eg:
class val;
rand bit [3:0] value;
endclass:val

implement a dist function
for
0:= 40;
1:3 := 60;

In reply to tex_mex:
For simplicity, I put everything into a module, but you can put the same function declaration in the class.


import uvm_pkg::*; `include "uvm_macros.svh" 
module top; 
    timeunit 1ns;     timeprecision 100ps;    
    bit clk; 
    bit[3:0] y;  
    initial forever #10 clk=!clk;  
 function  bit [3:0] my_rand ();
    automatic bit [3:0] w;
    if (!randomize(w)  with 
         { w dist {0 :=40, [1:3] :=60};
         })    `uvm_error("MYERR", "This is a randomize error");
    return w; 
 endfunction

initial begin 
    repeat(50) begin 
        @(posedge clk); 
        y=my_rand();   
        $display("y= %d", y); 
    end 
    $stop; 
end 
endmodule    

Ben Cohen
http://www.systemverilog.us/ ben@systemverilog.us
For training, consulting, services: contact Home - My cvcblr


See Paper: VF Horizons:PAPER: SVA Alternative for Complex Assertions | Verification Academy