标题: [数值计算] [已解决]BAT批处理如何生成随机排列组合 [打印本页]
作者: forliuning 时间: 2014-1-6 11:46 标题: [已解决]BAT批处理如何生成随机排列组合
本帖最后由 forliuning 于 2014-1-6 14:28 编辑
初学批处理应用,多次尝试不得要领,请教各位老师。
若有如下6组数值,每组有10个
如:
12,06,86,46,12,DF,55,SE,11,CA
F5,F4,DG,4S,6G,4S,65,ZG,14,65
ZS,D4,FG,SZ,1G,8S,ZD,4G,56,S4
GZ,SG,4S,D5,4G,FD,84,H5,6D,FY
7J,1T,Y6,K4,E6,84,54,87,E9,01
1K,HY,F1,K6,DR,4J,6R,D1,J5,RD
要求依次从每一组中随机抽取一个数值进行组合
结果显示其中一个随机组合结果并输出到1.TXT
例:466G8SFD01DR
呵呵,貌似密码卡的组合方式
十分感谢
作者: terse 时间: 2014-1-6 13:03
- @echo off&setlocal enabledelayedexpansion
- set "arr1=12,06,86,46,12,DF,55,SE,11,CA"
- set "arr2=F5,F4,DG,4S,6G,4S,65,ZG,14,65"
- set "arr3=ZS,D4,FG,SZ,1G,8S,ZD,4G,56,S4"
- set "arr4=GZ,SG,4S,D5,4G,FD,84,H5,6D,FY"
- set "arr5=7J,1T,Y6,K4,E6,84,54,87,E9,01"
- set "arr6=1K,HY,F1,K6,DR,4J,6R,D1,J5,RD"
- For /L %%i in (1,1,6) do (
- set /a rn=!random!%%10+1
- call:next !rn! "!arr%%i!" str
- )
- echo !str!
- pause&exit
- :next
- for /f "tokens=%1 delims=," %%i in (%2) do set "%3=!%3!%%i"
复制代码
作者: forliuning 时间: 2014-1-6 14:09
回复 2# terse
学习了。十分感谢!!!
作者: PowerShell 时间: 2014-1-6 15:38
powershell代码,都是些个简单的东西-
- $a = '12','06','86','46','12','DF','55','SE','11','CA' |Get-Random
- $b = 'F5','F4','DG','4S','6G','4S','65','ZG','14','65' |Get-Random
- $c = 'ZS','D4','FG','SZ','1G','8S','ZD','4G','56','S4' |Get-Random
- $d = 'GZ','SG','4S','D5','4G','FD','84','H5','6D','FY' |Get-Random
- $e = '7J','1T','Y6','K4','E6','84','54','87','E9','01' |Get-Random
- $f = '1K','HY','F1','K6','DR','4J','6R','D1','J5','RD' |Get-Random
-
-
- $结果 = "" + $a + $b + $c + $d + $e + $f
- Write-Host $结果
- #这个基本上就是,产生随机密码的脚本
复制代码
作者: terse 时间: 2014-1-6 16:20
PS 练手- $arr = @(
- "12,06,86,46,12,DF,55,SE,11,CA"
- "F5,F4,DG,4S,6G,4S,65,ZG,14,65"
- "ZS,D4,FG,SZ,1G,8S,ZD,4G,56,S4"
- "GZ,SG,4S,D5,4G,FD,84,H5,6D,FY"
- "7J,1T,Y6,K4,E6,84,54,87,E9,01"
- "1K,HY,F1,K6,DR,4J,6R,D1,J5,RD"
- )
- $str = foreach ( $a in $arr) {$a.split(",") | Get-Random}
- $str -join ""
复制代码
欢迎光临 批处理之家 (http://bathome.net./) |
Powered by Discuz! 7.2 |