I have written a test bench for my parameterized design in which I need to randomize the input. I got very surprised when I found out that if I run the following code, I get a nice random number for my 16 bit val:
val = $urandom_range(16'hffff, 0);
I use the following code to test my design with a 32 bit number (val[31:0]):
val = $urandom_range(32'hffff_ffff, 0);
however, in this case, I always get either 0 or 32'hffff_ffff. I don't know if this is a known bug in xilinx tools. I reduced my test code to the following and I still get same result:
initial begin
static print_verbosity verbosity = VERB_LOW;
static int unsigned num_tests = 1000;
int unsigned val;
for (int test_id=0; test_id<num_tests; test_id++) begin
val = $urandom_range(32'hffff_ffff, 0);
`test_print("INFO", $sformatf("val=%0d", val), verbosity)
end
$finish();
end
and the output I get is the following pattern:
[ INFO] val=0
[ INFO] val=4294967295
[ INFO] val=4294967295
[ INFO] val=0
[ INFO] val=4294967295
[ INFO] val=0
[ INFO] val=4294967295
[ INFO] val=0
I changed the upper boundary for urandom_range as follow:
val = $urandom_range(32'hefff_ffff, 0);
This time I got random numbers. I am wondering if someone can help me to find out where I am making mistake. I am using the latest Vivado 2018.2 simulator.
Confirmed using Vivado 2017.2:
module tst_urandom;
reg [31:0] numb1,numb2,numb3;
integer i;
initial
begin
for (i=0; i<20; i=i+1)
begin
numb1 = $urandom_range(32'hFFFFFFFF,0);
numb2 = $urandom_range(32'hFFFFFFFE,1);
numb3 = $urandom();
#10;
$display("0x%08X 0x%08X 0x%08X",numb1,numb2,numb3);
end
end
endmodule
Produces:
Vivado Simulator 2017.2
Time resolution is 1 ps
0x00000000 0xffffffff 0x8484d609
0xffffffff 0x00000000 0x46df998d
0xffffffff 0xfffffffe 0x00f3e301
0x00000000 0x00000000 0x1e8dcd3d
0x00000000 0x00000001 0x7cfde9f9
0xffffffff 0xffffffff 0xd513d2aa
0x00000000 0xfffffffe 0x8932d612
0x00000000 0x00000001 0xe77696ce
0xffffffff 0xffffffff 0x2e58495c
0xffffffff 0xfffffffe 0xb2a72665
0xffffffff 0x00000000 0xc03b2280
0x00000000 0x00000001 0xcecccc9d
0xffffffff 0xfffffffe 0x86bc380d
0xffffffff 0x00000000 0xeaa62ad5
0xffffffff 0xffffffff 0x0effe91d
0xffffffff 0x00000000 0x0509650a
I think you should file a bug report.