Elephant007 Posted October 22, 2010 Share Posted October 22, 2010 (edited) I'm looking for some direction to solving a problem I'm running into I have no idea where to start with this one, hopefully I'll provide good information to get the great help that's on these forums I have five servers, we'll call them Server01, Server1, Server2, Server3 and Server4 I need to come up with a script that will allow a computer to connect to one of these servers randomly. I know the 01 probably throws things off. I was hoping I could define the numbers 01, 1, 2, 3, 4 in the script and have that number put itself at the end of the server like SERVER# I have a batch script that does it (doesn't include server01 though) set num1=%random% set /a num2=%num1% * 4 set /a num3=%num2:~2,1% if /I "%num3%" LEQ "0" GOTO START if /I "%num3%" GEQ "5" GOTO START CAF setserveraddress server%num3% CAF register all Just some FYI, I'm needing this because we have Computer Associates Desktop IT Client Manager and need computers to connect to random servers as a means of load balancing since CA doesn't have load balancing capabilities Edited October 22, 2010 by Elephant007 Link to comment Share on other sites More sharing options...
water Posted October 22, 2010 Share Posted October 22, 2010 (edited) You could use the Random function. The following example will return a random server name. Global $aServer[5] = ["01", "1", "2", "3", "4"] For $iIndex = 1 To 10 ConsoleWrite("Server" & $aServer[Random(0, 4, 1)] & @CRLF) Next Edited October 22, 2010 by water My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
Elephant007 Posted October 22, 2010 Author Share Posted October 22, 2010 (edited) You could use the Random function. The following example will return a random server name. Global $aServer[5] = ["01", "1", "2", "3", "4"] For $iIndex = 1 To 10 ConsoleWrite("Server" & $aServer[Random(0, 4, 1)] & @CRLF) Next Thank you for your reply I think I'm going to go this route $LowerLimit = "1" $UpperLimit = "4" $RandomNumber = Random ( $LowerLimit, $UpperLimit, 1 ) MsgBox (0, "Random Number", $RandomNumber ) Now I'll go choke the admin for making a server named 01!!! Thank you again for your direction Edited October 22, 2010 by Elephant007 Link to comment Share on other sites More sharing options...
MvGulik Posted October 22, 2010 Share Posted October 22, 2010 (edited) Your sure ... adjusted version.Global $iThisServer = 0 Global $aServer[5] = ["DontCare1", "DontCare2", "DontCare3", "DontCare4", "DontCare5"] For $iIndex = 1 To 8 $iThisServer=Random(0, 4, 1) ConsoleWrite('$iThisServer = ' &$iThisServer& ', OtherServer = ' & RandomOtherServer($iThisServer, $aServer) & @CRLF) Next Func RandomOtherServer($iThisServer, $aServer) Local $iTmp = Random(0, UBound($aServer,1)-2, 1) If $iTmp >= $iThisServer Then $iTmp += 1 Return $iTmp EndFunc (Ps: needs a array with at least 3 entries. But there would be not much choice if its smaller than 3.) Edited October 22, 2010 by MvGulik "Straight_and_Crooked_Thinking" : A "classic guide to ferreting out untruths, half-truths, and other distortions of facts in political and social discussions.""The Secrets of Quantum Physics" : New and excellent 2 part documentary on Quantum Physics by Jim Al-Khalili. (Dec 2014) "Believing what you know ain't so" ... Knock Knock ... Link to comment Share on other sites More sharing options...
Elephant007 Posted October 22, 2010 Author Share Posted October 22, 2010 Thank you all for the replies, this is what I've done, maybe you can review my work and give me mods if required $LowerLimit = 0 $UpperLimit = 4 $RandomNumber = Random ( $LowerLimit, $ UpperLimit, 1 ) If $RandomNumber = "0" Then $RandomNumber = "01" MsgBox ( 0, "Test", "Random Number = " & $RandomNumber" ) I edited the code so it only selected 0 and the message box gave me 01 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now