From: Confused Scripter on
Hello,

I have a text file with a list of hostnames in it. I want this list to
be reorganised randomly anyone got any idea how to do this in VBS or
Batch file language

Cheers

Dan
From: Michael Harris (MVP) on
> I have a text file with a list of hostnames in it. I want this list to
> be reorganised randomly anyone got any idea how to do this in VBS or
> Batch file language

Read the file into an array and then shuffle it...

How do I shuffle a list of items in WHS?
http://groups-beta.google.com/group/microsoft.public.scripting.wsh/browse_thread/thread/c33b4a9b62c9d1a3

--
Michael Harris
Microsoft.MVP.Scripting

From: Torgeir Bakken (MVP) on
Michael Harris (MVP) wrote:

>>I have a text file with a list of hostnames in it. I want this list to
>>be reorganised randomly anyone got any idea how to do this in VBS or
>>Batch file language
>
>
> Read the file into an array and then shuffle it...
>
> How do I shuffle a list of items in WHS?
> http://groups-beta.google.com/group/microsoft.public.scripting.wsh/browse_thread/thread/c33b4a9b62c9d1a3
Hi

A ready script using the function in the post above (be sure that
the file you read in does not have a blank line at the end or you
will end up having a blank entry in the list):


'--------------------8<----------------------
Const ForReading = 1
Const OpenAsASCII = 0
Const FailIfNotExist = 0

Set objFSO = CreateObject("Scripting.FileSystemObject")

strInFile = "C:\hostnames.txt"

Set objFile = objFSO.OpenTextFile(strInFile, _
ForReading, FailIfNotExist, OpenAsASCII)

arData = Split(objFile.ReadAll, vbNewLine)
objFile.Close

WScript.Echo Join(arData,";")

arShuffled = Shuffle(arData)

WScript.Echo Join(arShuffled,";")


Function Shuffle(arIn)
' Durstenfeld's Permutation Algorithm
Dim J, K, Temp
Dim arOut
arOut = arIn
Randomize
For J = UBound(arOut) To 1 Step -1
K = Int((J + 1) * Rnd) ' random number 0 - J
Temp = arOut(J)
arOut(J) = arOut(K)
arOut(K) = Temp
Next
Shuffle = arOut
End Function
'--------------------8<----------------------



--
torgeir, Microsoft MVP Scripting and WMI, Porsgrunn Norway
Administration scripting examples and an ONLINE version of
the 1328 page Scripting Guide:
http://www.microsoft.com/technet/scriptcenter/default.mspx
From: CoFuzed ScrIpter on
Hello and thanks for your help. How do I then rewrite these results to
the text file ??

Thanks in advance for your help

Dan

From: Dan Bowden on
Thankyou for your speedy response on randomising a text file question.
I was wondering how would I set this to output it back into a text
file. Also is it possible to write VBS in such a way so that I could
drag a txt file over the script and it would use that file, randomise
it and overwrite the original?

Thanks again you have been very helpful

Dan

Torgeir Bakken (MVP) wrote:
> Michael Harris (MVP) wrote:
>
> >>I have a text file with a list of hostnames in it. I want this list
to
> >>be reorganised randomly anyone got any idea how to do this in VBS
or
> >>Batch file language
> >
> >
> > Read the file into an array and then shuffle it...
> >
> > How do I shuffle a list of items in WHS?
> >
http://groups-beta.google.com/group/microsoft.public.scripting.wsh/browse_thread/thread/c33b4a9b62c9d1a3
> Hi
>
> A ready script using the function in the post above (be sure that
> the file you read in does not have a blank line at the end or you
> will end up having a blank entry in the list):
>
>
> '--------------------8<----------------------
> Const ForReading = 1
> Const OpenAsASCII = 0
> Const FailIfNotExist = 0
>
> Set objFSO = CreateObject("Scripting.FileSystemObject")
>
> strInFile = "C:\hostnames.txt"
>
> Set objFile = objFSO.OpenTextFile(strInFile, _
> ForReading, FailIfNotExist, OpenAsASCII)
>
> arData = Split(objFile.ReadAll, vbNewLine)
> objFile.Close
>
> WScript.Echo Join(arData,";")
>
> arShuffled = Shuffle(arData)
>
> WScript.Echo Join(arShuffled,";")
>
>
> Function Shuffle(arIn)
> ' Durstenfeld's Permutation Algorithm
> Dim J, K, Temp
> Dim arOut
> arOut = arIn
> Randomize
> For J = UBound(arOut) To 1 Step -1
> K = Int((J + 1) * Rnd) ' random number 0 - J
> Temp = arOut(J)
> arOut(J) = arOut(K)
> arOut(K) = Temp
> Next
> Shuffle = arOut
> End Function
> '--------------------8<----------------------
>
>
>
> --
> torgeir, Microsoft MVP Scripting and WMI, Porsgrunn Norway
> Administration scripting examples and an ONLINE version of
> the 1328 page Scripting Guide:
> http://www.microsoft.com/technet/scriptcenter/default.mspx