The Designer's Guide Community
Forum
Welcome, Guest. Please Login or Register. Please follow the Forum guidelines.
Apr 19th, 2024, 3:37am
Pages: 1
Send Topic Print
$random always generates the same value (Read 5012 times)
Lucho
New Member
*
Offline



Posts: 5
Bucaramanga - Colombia
$random always generates the same value
Apr 08th, 2014, 1:11pm
 
Hi have the following verilog-a block for a random number generator:

--

// VerilogA for Example, RdnGen, veriloga

`include "constants.vams"
`include "disciplines.vams"

module RdnGen(out);

output out;
electrical out;

integer randn;
integer sign;

analog begin

randn = $random %60;
sign = (randn < 0) ? 1:-1;

@(initial_step)

$strobe

("Rand\t\t",randn,
"\n", "Sign\t\t", sign,
"\n\n\n\n\n");

end
endmodule
~            

--

I don't understand why every single time I run this code the "randomly" generated number is always the same.

Any hints ?

Thank you,
Back to top
 
 
View Profile WWW Lucho Lucho lucho_lazaro   IP Logged
Andrew Beckett
Senior Fellow
******
Offline

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

Posts: 1742
Bracknell, UK
Re: $random always generates the same value
Reply #1 - Apr 9th, 2014, 11:21pm
 
The seed is such that simulations are reproducible - you run the same simulation twice, you'll get the same answer.

Andrew.
Back to top
 
 
View Profile WWW   IP Logged
Lucho
New Member
*
Offline



Posts: 5
Bucaramanga - Colombia
Re: $random always generates the same value
Reply #2 - Apr 10th, 2014, 11:20am
 
Thank you very much for your answer,

However, we've observed that for IC5.1 that is not the case, as for each DC op point simulation we obtain a different randomly generated number. This issue has appeared in the virtuoso 6.1.5 version.

As a secondary question, what would be an alternative then to obtain a randomly generated sign (+ or -) for a signal that would be used as a DC offset for an amplifier model ?

Regards,

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



Posts: 1998
Massachusetts, USA
Re: $random always generates the same value
Reply #3 - Apr 16th, 2014, 10:51am
 
The LRM says
"The random_seed argument may take one of several forms. It may be omitted, in which case the simulator picks a seed."

It sounds like the simulator changed how it picks the seed between the different versions.

To work around this, you'll need to specify a seed, probably by passing in the trial number of the simulation.
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.