RegisterLogin  
Update Profile
   
You are here: Forum  
Minimize 
SVUG Community Forum
Subject: Doubt on $urandom
Prev Next
You are not authorized to post a reply.

Author Messages
VISHNU PRASANTHUser is Offline

Posts:3

12/07/2007 6:07 AM  

When I used $random(seed) the seed value also changing for repeated calls.
But for $urandom(seed) why seed value is not changing. I am using questasim 6.2b.
See the program below.
module Tb();
integer numr,numu,seedr,seedu,i,j;
initial
begin
seedr = 2;seedu = 2;numr = 10;numu = 10;
for(j = 0;j<2 ;j=j+1)
begin
$display(" seed for urandom = %d seed for random = %d ",seedu,seedr);
for(i = 0;i < 6; i=i+1)
begin
$display("Iteration %d",i);
numu =  $urandom(seedu)  % 10;
numr =  $random(seedr)  % 10;
$write("| seed(urandom) = %2d num(urandom)=%2d \nseed(random) = %2d num(random)=%2d |\n",seedu,numu,seedr,numr);
end
display(" ");
end
end
endmodule
OUTPUT:
#  seed for urandom =           2 seed for random =           2
# Iteration           0
# | seed(urandom) =  2 num(urandom)= 7
# seed(random) = 138139 num(random)=-8 |
# Iteration           1
# | seed(urandom) =  2 num(urandom)= 7
# seed(random) = 951188000 num(random)=-5 |
# Iteration           2
# | seed(urandom) =  2 num(urandom)= 7
# seed(random) = 1784212385 num(random)=-6 |
# Iteration           3
# | seed(urandom) =  2 num(urandom)= 7
# seed(random) = -1731404562 num(random)= 5 |
# Iteration           4
# | seed(urandom) =  2 num(urandom)= 7
# seed(random) = -1607270249 num(random)= 0 |
# Iteration           5
# | seed(urandom) =  2 num(urandom)= 7
# seed(random) = -529128468 num(random)= 8 |

If u observe the output, when I used the $random(seed) function the internal seed value and number is also automatically changing. But with $urandom the seed value is not changing, so number is also not changing. Can u get back to me how I can use seed with $urandom.
DAVEUser is Offline

Posts:56

12/09/2007 10:55 PM  
The functionality of the seed arguments are different for $random and $urandom. The seed argument to $random is an inout. It updates its seed argument after each call to $random. This means the internal random number generator (RNG) state variable is a 32-bit number. The seed argument to $urandom is an input. This seed is used to set the internal RNG to a value that is over 32-bits (typically 96-bits or greater).

In SystemVerilog, each thread has its own RNG, so only use the the seed argument on the first call to $urandom in each thread. There is also a way to set the seed without generated a random value by using the built-in process class and using the srandom() method.

Dave
VISHNU PRASANTHUser is Offline

Posts:3

12/11/2007 3:13 AM  
Hi Dave,

How i can i use seed argument on the first call to $urandom in each thread. how seed will change for nextcalls to $urandom.







DAVEUser is Offline

Posts:56

12/11/2007 10:26 AM  
Each thread maintains its own internal seed. There's no need to pass the seed around. See the section on Random Stability in the LRM.

Dave
VISHNU PRASANTHUser is Offline

Posts:3

12/11/2007 10:51 PM  
I got it Dave. Thankyou
GOPIUser is Offline

Posts:3

12/13/2007 12:58 AM  
So what is the need of the optional argument in $urandom?
If the $urandom is called inside module, is it going to get seed from parent thread?
So, random stability concept is applied to module based testbenches ?

gopi@testbench.in
-- systemverilog, Verilog, Openvera, VMM ,RVM and AVM tutorials
www.testbench.in
You are not authorized to post a reply.



ActiveForums 3.7
  

 Copyright 2008 by SystemVerilog User Group Contact Us    Privacy Statement