Hello,
I’ve found in our testbench some code that uses $random to create some delay inside a module, I have read about random stability when creating objects and that you should use $urandom_range, std::random, .randomize() to keep random stability, I personally know little about the topic (specially in modules) so I’d like to get some advice to come with an argument on why this code should changed (if this is the case)
Keep in mind I do understand this implementation can be improved (you can use a function instead of using a module and the its function call, I could use $urandom_range), the correctness of the code is not what I’m asking it is about why you shouldnt (if that is the case) use $random
`timescale 1ns/10ps
module a_module
(
// Inputs
input logic clk,
input logic reset,
input logic valid,
output logic delay;
);
delay_gen_module delay_gen();
always @(posedge clk_in) begin
if (~reset_L) begin
//do reset stuff
end
else begin
if(valid) begin
delay <= delay_gen.create_delay();
//do some stuff with delay
end
end
end
endmodule
// delay gen module
module delay_gen_module();
function integer create_delay;
input a;
input b;
integer a;
integer b;
integer aux;
begin
aux = $random;
//do some stuff and return a delay
end
endfunction
endmodule
Thanks,
-R