Jump to content

[Done] Select Predefind Numbers Randomly


Recommended Posts

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 by Elephant007
Link to comment
Share on other sites

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 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 - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

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 by Elephant007
Link to comment
Share on other sites

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

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

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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...