Jump to content
Sign in to follow this  
wisem2540

Need to pull a random static value from somewhere to a variable

Recommended Posts

wisem2540

I have an app that can point to 1 of 4 servers. In an effort to pseudo load balance, everytime I launch the app, I would like a different server to appear in the server box. I assume I could control this by doing a regwrite.

I could put the 4 server names into an array I suppose, or read them from a text file. but how can I get autoit to choose one of them at random and store it to a variable?

Share this post


Link to post
Share on other sites
water

Check function Random.

$iNumber = Random(1, 4, 1)
willl give you an interger between 1 an 4.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
wisem2540

Just so im clear, would I then use this integer to reference a line in a theoretical array?

Share this post


Link to post
Share on other sites
water

Correct.

Example:

Global $aServer[4] = ["Server1", "Server2", "Server3", "Server4"]
$sServerToUse = $aServer[Random(0, 3, 1)] ; 0 - 3 because the index of an array starts with 0
Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
wisem2540

Water,

thanks. I added a regread to get the current value. Then a Do-Until $Currentvalue <> $sServerToUse, to prevent it from returning the same value consecutively. - then obviously a regwrite on $sServertoUse. It works well.

Thanks again.

Share this post


Link to post
Share on other sites
water
:D

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×