本帖最后由 apang 于 2012-12-13 23:24 编辑
存放网址的文件为a.txt,生成新文件b.txt。代码保存为test.bat与a.txt放在一起- @echo off&setlocal enabledelayedexpansion
- set N=12
- for /f "delims=" %%a in (a.txt) do (
- set /a L+=1
- set "_!L!=%%a"
- )
- if %N% gtr %L% set N=%L%
- (for /l %%a in (1 1 %N%) do call :Loop)>b.txt
- goto :eof
-
- :Loop
- set /a r=%random% %% L + 1
- if defined .%r% (goto :Loop) else set .%r%=1&echo,!_%r%!
复制代码 vbs,只是练习。。。- N = 6
- Set FSO = CreateObject("Scripting.FileSystemObject")
- Text = FSO.OpenTextFile("a.txt",1).ReadAll
- Arr = Split(Text,vbCrLf)
- ReDim B(Ubound(Arr))
- If N > UBound(Arr) + 1 Then N = UBound(Arr) + 1
- Do Until N = i
- Randomize
- r = Int((Ubound(Arr) + 1)* Rnd)
- If B(r) = "" Then
- Str = Str & Arr(r) & vbCrLf
- B(r) = "1" : i = i + 1
- End If
- Loop
- FSO.OpenTextFile("b.txt",2,True).Write Str
- MsgBox "OK"
复制代码
|