The Designer's Guide Community
Forum
Welcome, Guest. Please Login or Register. Please follow the Forum guidelines.
Apr 26th, 2024, 1:56am
Pages: 1
Send Topic Print
generate two different random integers on HSPICE (Read 2687 times)
AA
Junior Member
**
Offline



Posts: 21

generate two different random integers on HSPICE
Nov 19th, 2016, 12:47pm
 
Is there a way to generate two distinct random integers on HSPICE?

For example, I can generate two random integers, a and b, from 0 to 9 as follows:
Code:
.param rng = aunif(5, 5)
.param a = int(rng)
.param b = int(rng)
 



However, I want a and b to be two different numbers, with some sort of randomness.
The code above may generate the same value for a and b. How to make sure a and b are always different and within the range?
Back to top
 
« Last Edit: Nov 19th, 2016, 3:19pm by AA »  
View Profile   IP Logged
Geoffrey_Coram
Senior Fellow
******
Offline



Posts: 1998
Massachusetts, USA
Re: generate two different random integers on HSPICE
Reply #1 - Nov 21st, 2016, 12:12pm
 
Why not do
Code:
.param a = aunif(5, 5)
.param b = aunif(5, 5)
 


?
Back to top
 
 

If at first you do succeed, STOP, raise your standards, and stop wasting your time.
View Profile WWW   IP Logged
AA
Junior Member
**
Offline



Posts: 21

Re: generate two different random integers on HSPICE
Reply #2 - Nov 22nd, 2016, 3:32pm
 
Two reasons:
(1) I need a and b to be integers
(2) I need a and b to be different numbers on every Monte Carlo iteration ,i.e., when performing MONTE sweep. For example, if a=4, then b cannot be 4. In other words, the random number generator should reject the value of b when it equals to a, and keeps regenerating b until b!=a.

The code you provided may generate the same value for a and b (especially when converted to integers) in the subsequent Monte Carlo iterations.

I hope there is a way to do this in HSPICE. Otherwise, I will probably need to write a Verilog-A module. Also, if this is not possible in HSPICE, please provide a hint on the best way to implement this functionality on Verilog-A. I especially need to know how to consume the Verilog-A module's outputs (a and b) as HSPICE parameters.
Back to top
 
 
View Profile   IP Logged
Geoffrey_Coram
Senior Fellow
******
Offline



Posts: 1998
Massachusetts, USA
Re: generate two different random integers on HSPICE
Reply #3 - Nov 28th, 2016, 10:48am
 
I missed the point that you want to enforce a != b, sorry.

What about something like

Code:
.param a = int(aunif(5,5))
.param temp = int(aunif(5,4.5)-0.5)
.param b = (a == temp) ? 9 : temp
 



'temp' should be from 0 to 8, and when it's the same as a, b is set to 9.
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.