The Designer's Guide Community
Forum
Welcome, Guest. Please Login or Register. Please follow the Forum guidelines.
May 5th, 2024, 11:49am
Pages: 1
Send Topic Print
Random behavior of $random() in SpectreHDL (Read 5398 times)
vivkr
Community Fellow
*****
Offline



Posts: 780

Random behavior of $random() in SpectreHDL
Jul 17th, 2006, 12:04am
 
Hi,

I wonder if the $random() function is recomputed each time a new analysis runs.
I have an AHDL block where I generate a random number in the "initial" section of
the code, and store it in a local variable, which is used in the "analog" section to
output a random voltage.

The DC output is different when seen by annotating or printing the DC operating point
of the circuit, as compared to the DC level seen in the transient analysis. There appears
to be no correlation between the quantities either.

Is this normal behavior? The core of the code is quite simply:

real x;

initial{
x=random();
}

analog{
V(out) <- vref*x;
}

Regards
Vivek
Back to top
 
 
View Profile   IP Logged
Geoffrey_Coram
Senior Fellow
******
Offline



Posts: 1998
Massachusetts, USA
Re: Random behavior of $random() in SpectreHDL
Reply #1 - Jul 20th, 2006, 4:18am
 
The LRM says that, since you did not specify a seed, the simulator picks one, and I guess it picks a different one for each analysis.

If you want a consistent value, then you should specify a seed.

real x;
int seed;

initial begin
 seed = 123;
 x = random(seed);
end

analog
 V(out) <+ vref * x;

Back to top
 
 

If at first you do succeed, STOP, raise your standards, and stop wasting your time.
View Profile WWW   IP Logged
Andrew Beckett
Senior Fellow
******
Offline

Life, don't talk to
me about Life...

Posts: 1742
Bracknell, UK
Re: Random behavior of $random() in SpectreHDL
Reply #2 - Jul 24th, 2006, 1:42pm
 
Note, SpectreHDL is end-of-lifed - in fact it has gone in MMSIM61, the latest release of spectre. So don't use it... use Verilog-A. Geoffrey's answer was for Verilog-A.

There was a fix recently to do with repeatability of random numbers (I think all instances ended up with the same
sequence, when no seed was specified, and that was fixed) - but I can't remember precisely what it was...

Andrew.
Back to top
 
 
View Profile WWW   IP Logged
Geoffrey_Coram
Senior Fellow
******
Offline



Posts: 1998
Massachusetts, USA
Re: Random behavior of $random() in SpectreHDL
Reply #3 - Jul 31st, 2006, 7:21am
 
Andrew Beckett wrote on Jul 24th, 2006, 1:42pm:
Geoffrey's answer was for Verilog-A.


Oops, thanks Andrew.  I guess I didn't read the subject closely.
Back to top
 
 

If at first you do succeed, STOP, raise your standards, and stop wasting your time.
View Profile WWW   IP Logged
Pages: 1
Send Topic Print
Copyright 2002-2024 Designer’s Guide Consulting, Inc. Designer’s Guide® is a registered trademark of Designer’s Guide Consulting, Inc. All rights reserved. Send comments or questions to editor@designers-guide.org. Consider submitting a paper or model.