Sign in to follow this  
Followers 0
Elephant007

[Done] Select Predefind Numbers Randomly

5 posts in this topic

#1 ·  Posted (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 by Elephant007

Share this post


Link to post
Share on other sites



#2 ·  Posted (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 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

#3 ·  Posted (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 by Elephant007

Share this post


Link to post
Share on other sites

#4 ·  Posted (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 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 ...
 

Share this post


Link to post
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

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