Randomize tuple to single string

Looking to randomize the _BESClient_RelaySelect_FailoverRelayList list. So I want to take a list like (“server1”; “server2”; “server3”; “server4”) and populate FailoverRelayList = “server2,server3,server4,server1” (or what ever “random” or rotated list.

Ideas?

Since you are going to be setting the _BESClient_RelaySelect_FailoverRelayList using an action, then you should randomize the list using something like VBScript during the action execution.

Randomness is difficult in Relevance. It is definitely something that would be useful if added to the inspector options.

Unique values will sort a list alphabetically. It would be interesting if there was something to sort a list randomly.

Best way I have found so far is to use time.

(it as integer ) of second_of_minute of time (local time zone) of now / (60 / ( number of unique values of ("server1";"server2";"server3"; "server4")))

At least splits things up. If we could figure out where to say, “start at index 3 of the array, and cycle through”.

I guess I could put the list in a parameter and vbs the array list. Would have been nice to figure that out in the action script when setting the value. I’ll write up the vbs.

I was thinking the same about using seconds. It’ll introduce some form of arbitrary ordering.

So pick 1 from 4 candidates, then 1 from remaining 3 candidates, then 1 from remaining 2 candidates.

1 Like

You can do it as @gearoid suggests purely using relevance & actionscript, but it will be dependent on the number of failover relays that are being chosen from.

Also, If you do use VBS, then I would recommend using the createfile option so that you can use relevance substitution to make it easier. The advantage of the VBS approach is that it would not be dependent on the number of relays in the list.

Also, I would recommend basing the randomness on the computer id which will make each computer pick the list differently, but it would be deterministic for that particular computer.

The way you would do it in relevance is something like this: (this is not the actual complete relevance)

Pick1 = tuple string item (computer id mod 4) of concatenations ", " of ("server1"; "server2"; "server3"; "server4")
Pick2 = tuple string item (computer id mod 3) of concatenations ", " of ("server1"; "server2"; "server3"; "server4") whose(it != Pick1)
Pick3 = tuple string item (computer id mod 2) of concatenations ", " of ("server1"; "server2"; "server3"; "server4") whose(it != Pick1 AND it != Pick2)
1 Like

Here’s what I came up with. Let me know what you think. I got the “randomness” off the seconds.

parameter "_List" = "server1.comp.com;server2.comp.com;server3.comp.com;server4.comp.com"
parameter "_ListPrefix" = "localRelay1;localRelay2"
parameter "_ListSuffix" = "dmz.comp.com"

parameter "_ListFile" = "c:\ProgramData\List.txt"
parameter "_ListScript" = "c:\ProgramData\failover.vbs"

delete __FileCreate
delete {parameter "_ListFile"}
delete {parameter "_ListScript"}

createfile until __FileCreate
option explicit
on error resume next
Dim DataList, objFile, objFSO
Set DataList = CreateObject ("System.Collections.ArrayList")
Set objFSO=CreateObject("Scripting.FileSystemObject")

Dim sServerDNS, sServerSplit, sServerDMZ, sServerOut, sServerBuild
sServerDNS = "{parameter "_ListPrefix"}"
sServerSplit = "{parameter "_List"}"
sServerDMZ = "{parameter "_ListSuffix"}"
sServerOut = ""
sServerBuild = ""

Dim sOutputFile
sOutputFile="{parameter "_ListFile"}"

Set objFile = objFSO.CreateTextFile(sOutputFile,True)

dim aServerSplit, i
aServerSplit = split(sServerSplit,";")
For i = 0 To ubound(aServerSplit)
	DataList.Add aServerSplit(i)
next

Dim n
Do Until DataList.count = 0
	n=int(( int(right(second(now), 1))/10)* DataList.count)
	if (len(sServerBuild) = 0) then
		sServerBuild = sServerBuild & DataList(n)
	else
		sServerBuild = sServerBuild & ";" & DataList(n)
	end if
	DataList.Remove(DataList(n))
loop

sServerOut = sServerDNS & ";" & sServerBuild & ";" & sServerDMZ

objFile.Write sServerOut
wscript.echo sServerOut
__FileCreate

move __createfile "{parameter "_ListScript"}"
wait cscript.exe "{parameter "_ListScript"}"

parameter "line" = "{line 1 of file "c:\ProgramData\List.txt"}"
setting "_BESClient_RelaySelect_FailoverRelayList"="{parameter "line"}" on "{parameter "action issue date" of action}" for client
setting "_BESClient_RelaySelect_TertiaryRelayList"="{parameter "line"}" on "{parameter "action issue date" of action}" for client

delete {parameter "_ListFile"}
delete {parameter "_ListScript"}

// Force client to send update to relay
relay select

I haven’t got through it all yet, but I don’t like the use of c:\ProgramData. I would recommend using either the BES Client Downloads folder for the current site, or use C:\Windows\Temp


This is definitely harder to follow because the parameters and the variables names don’t match. I find that a tad confusing.

I would change the parameters and variables to: sList, sListPrefix, sListSuffix


So the process seems to be that you have a set of relays that should always be at the beginning of the list, a set that should always be at the end, and then a middle set that should be randomized.

Is that correct?


why are you setting _BESClient_RelaySelect_TertiaryRelayList and _BESClient_RelaySelect_FailoverRelayList to the exact same thing? That seems redundant.


One of the issues with using seconds is if you send this out to 1000 or so servers all at the same time, most of them are going to run it at a very similar timing. The advantage of VBScript over relevance is that you can use true randomness to pick a selection.

Here are a few options to help do this:

1 Like

You’re killing me James, but I’ll take the criteek. I just wrote the script in one editor and added the file create parameters in QnA. Just ended up that way when I was done. I’ll move things to Windows\Temp, but the script cleans things up after it self.

I some googling on the “Rnd” variable and it has been my experience that it’s not so random. Only reason I had that snippit of code around. That said, I didn’t initialize the “randomness”. That said, it’s working and it random enough for me. :smiley:

Regarding TertiaryRelayList & FailoverRelayList, I couldn’t get things to actually fail over to the list and not to got he root without setting both. Just something I hit my head on a a while back so I just set both and things work well.

Thanks for pointing me in the right direction!

2 Likes

You are welcome. Sorry if I seem harsh. There isn’t anything wrong with your script, just jotting down my thoughts as I went.

I’m not sure of the best way to achieve good randomness in VBScript, but I figure there must be a reasonable way to do it.

Not harsh. Just giving your observations. They were good ones. :+1:

1 Like

This is interesting. This probably would have been worth a PMR or a post here to really document when and how this happens and what the issues are… of course, this is asking a lot, especially far after the fact.

I do wonder how bad of an issue it is.