$random with seed parameter

I want to know if I have to generate a set of random numbers using $random such that every time the simulation runs,the same set of random numbers are generated then how to do?

Thanks
Susmita

In reply to sush:

Please try giving a fixed seed as argument to $random

int fixed_seed =10;
$random (fixed_seed)

In reply to abhilash1106:

There’s no need to supply a seed. Any random number generator should generate the same series of random values every time it is run, as long as there is no change to the source code. And the trick is to have the same series of random values when you DO change the source code.

SystemVerilog calls this Random Stability. SystemVerilog defines how random number generators get independently seeded, and what modifications to the source code would either preserve or disturb the seeding.

Verilog’s $random does not have this feature, you have to manually provide seed arguments and keep track of all the seeds yourself. So use $urandom instead $random.

In reply to dave_59:

I understand your concepts.

Please analyze the below code:


module random;
reg [31:0]a;

initial
begin
repeat(5)
begin 
#10 a =$urandom(100);
$display(a);
end
#10 $finish;
end

endmodule

Expected Observation:I was expecting 5 different random numbers which will be fixed every time simulation runs.

But after I pass the seed number 100,I am getting identical 5 random numbers every time the simulation runs.

Can you please elaborate?

Thanks
Susmita

In reply to sush:

You should not supply a seed argument; just use $urandom;. By providing a seed, you are re-initializing the random number generate with the same initial value each time it is called.

Please read section 18.14 in the 1800-2017 LRM

In reply to dave_59:

Thanks I am clear now.

In reply to sush:

Dear Dave/Abhilash,

I was just reading the LRM for RNG,it is mentioned there that the
function $urandom returns a new 32-bit random number each time it is called but every time I execute the below code I get the same random number.

#################################################
reg [31:0]a;

initial
begin

  begin 
   #10 a =$urandom;
   $display(a);
  end
  #10 $finish;
end

#####################################################