Sign in to follow this  
Followers 0
wisem2540

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

6 posts in this topic

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

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 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

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

#4 ·  Posted (edited)

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 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

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
:D

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

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  
Followers 0