BartlebyScrivener
Member level 5
Problems with SystemVerilog random number generation
For my test bench I need lots of independent random numbers. I have about 5 instances where I use a for loop and $urandom_range(x,y) to generate a selction of random numbers fine. However, I now want to be able to perform multiple runs of the simulation, changing the random number pattern each time. I looked in the standard, and it didn't appear that urandom_range accepts a seed, so I tried dist_uniform. But it doesn't work.
I wrote a basic test bench to see what the values I was getting were.
and it appears the dist_uniform value remains constant irrespective of the for loop and irrespective of the for loop and clk?!
Is there a simple way to modify urandom_range so that I can ask for a new pattern?
How can I do this? Thanks.
For my test bench I need lots of independent random numbers. I have about 5 instances where I use a for loop and $urandom_range(x,y) to generate a selction of random numbers fine. However, I now want to be able to perform multiple runs of the simulation, changing the random number pattern each time. I looked in the standard, and it didn't appear that urandom_range accepts a seed, so I tried dist_uniform. But it doesn't work.
I wrote a basic test bench to see what the values I was getting were.
Code Verilog - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 module forloop; logic clk; initial begin clk = 1; forever #(1ns) clk = ~clk; end initial begin forever@(posedge clk) begin for (int i=0; i<10; i++) begin $display("DU %g: %g", i, $dist_uniform(0, 1, 100)); $display("UR %g: %g", i, $urandom_range(1, 100)); end end end endmodule
and it appears the dist_uniform value remains constant irrespective of the for loop and irrespective of the for loop and clk?!
Is there a simple way to modify urandom_range so that I can ask for a new pattern?
How can I do this? Thanks.
Last edited: