Break ON
$=SetOption("Explicit","ON")
$=SetOption("WrapAtEOL","ON")
$=SetOption("ANSI","ON")
Dim $sDebug $sDebug=1 ; Set to 1 to display debug messages, 0 to suppress
Dim $sFolderPath,$sInputPath,$sOutputPath, $sLastPath
Dim $iPick,$fso,$oInputFile,$oLastFile
Dim $asInputList, $sLastList, $iChose
$sFolderPath="D:\TEMP\" ; Folder containg data files
$sInputPath=$sFolderPath+"InputList.txt" ; File containing list to select from
$sLastPath=$sFolderPath+"InputList.old" ; Last week's file (copy of above
$sOutputPath=$sFolderPath+"OutputList.txt" ; Selected items
$iPick=5 ; Number of items to select
$=SRND(@MSECS)
$=RND(0)
; Copy last week's selections to backup file
Copy $sOutputPath $sLastPath
; Load up the original list
$fso = CreateObject("Scripting.FileSystemObject")
$oInputFile = $fso.OpenTextFile($sInputPath,Not 0)
$asInputList=Split($oInputFile.ReadAll,@CRLF)
$oInputFile.Close
; Load up last weeks selections
$oLastFile = $fso.OpenTextFile($sLastPath,Not 0)
$sLastList=@CRLF+$oLastFile.ReadAll+@CRLF
$oLastFile.Close
$=Open(1,$sOutputPath,5) ;Generating output file list
While $iPick
$asInputList=Split(udfSqueeze(Join($asInputList,@CRLF),@CRLF),@CRLF)
$iChose=IIf(UBound($asInputList)>0,RND(UBound($asInputList)),0)
If $sDEBUG "Selection "+$iPick+": "+$asInputList[$iChose]+@CRLF EndIf ; *DEBUG*
If $asInputList[$iChose]=""
If $sDEBUG " Input list exhausted - aborting."+@CRLF EndIf ; *DEBUG*
Exit 259
EndIf
; If the item was previously selected then abandon it
If InStr($sLastList,@CRLF+$asInputList[$iChose]+@CRLF)
If $sDebug " Selection dropped as used last week"+@CRLF EndIf ; *DEBUG*
Else
$=WriteLine(1,$asInputList[$iChose]+@CRLF)
$iPick=$iPick-1
EndIf
$asInputList[$iChose]=""
Loop
$=Close(1)
Function udfSqueeze($s,$q)
$udfSqueeze=$q+$s+$q
While InSTR($udfSqueeze,$q+$q)
$udfSqueeze=Join(Split($udfSqueeze,$q+$q),$q)
Loop
$udfSqueeze=Split($q+$udfSqueeze+$q,$q+$q)[1]
EndFunction