How can I randomize say 1-bit two inputs (in0, in1) such that each has uniform distribution of input values; say input = 0 30%, input =1 30%, input = x 20% and input = z 20%?
In reply to emad hamadeh:
import uvm_pkg::*; `include "uvm_macros.svh"
// How can I randomize say 1-bit two inputs (in0, in1)
// such that each has uniform distribution of input values;
// say input = 0 30%, input =1 30%, input = x 20% and input = z 20%?
module top;
logic in0, in1;
logic [1:0] a, b;
initial begin : init1
repeat(10) begin : rpt1
if (!randomize(a, b) with
{ a dist {2'b00:=3, 2'b01:=3, 2'b10 :=2, 2'b11 :=2 };
b dist {2'b00:=3, 2'b01:=3, 2'b10 :=2, 2'b11 :=2 };
}) `uvm_error("MYERR", "This is a randomize error")
case (a)
2'b00 : in0=1'b0;
2'b01 : in0=1'b1;
2'b10 : in0=1'bX;
2'b11 : in0=1'bZ;
endcase
case (b)
2'b00 : in1=1'b0;
2'b01 : in1=1'b1;
2'b10 : in1=1'bX;
2'b11 : in1=1'bZ;
endcase
$display("a=%d, b=%d, in0=%b, in1=%b", a, b, in0, in1);
end : rpt1
end : init1
endmodule
// simulation results
a=1, b=2, in0=1, in1=x
# a=1, b=3, in0=1, in1=z
# a=3, b=0, in0=z, in1=0
# a=3, b=1, in0=z, in1=1
# a=2, b=0, in0=x, in1=0
# a=2, b=1, in0=x, in1=1
# a=0, b=0, in0=0, in1=0
# a=2, b=1, in0=x, in1=1
# a=1, b=0, in0=1, in1=0
# a=0, b=2, in0=0, in1=x
Ben Cohen
http://www.systemverilog.us/ ben@systemverilog.us
- SVA Handbook 4th Edition, 2016 ISBN 978-1518681448
- A Pragmatic Approach to VMM Adoption 2006 ISBN 0-9705394-9-5
- Using PSL/SUGAR for Formal and Dynamic Verification 2nd Edition, 2004, ISBN 0-9705394-6-0
- Real Chip Design and Verification Using Verilog and VHDL, 2002 isbn 978-1539769712
- Component Design by Example ", 2001 ISBN 0-9705394-0-1
- VHDL Coding Styles and Methodologies, 2nd Edition, 1999 ISBN 0-7923-8474-1
- VHDL Answers to Frequently Asked Questions, 2nd Edition ISBN 0-7923-8115
In reply to emad hamadeh:
If it’s a uniform distribution then the probability for each value would be 0.25. What you’re asking for is a weighted distribution.
In reply to ben@SystemVerilog.us:
thanks a lot Ben…I had to change this a bit to make it as a two dimensional array.