Board logo

标题: [数值计算] [已解决]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

  1. @echo off&setlocal enabledelayedexpansion
  2. set "arr1=12,06,86,46,12,DF,55,SE,11,CA"
  3. set "arr2=F5,F4,DG,4S,6G,4S,65,ZG,14,65"
  4. set "arr3=ZS,D4,FG,SZ,1G,8S,ZD,4G,56,S4"
  5. set "arr4=GZ,SG,4S,D5,4G,FD,84,H5,6D,FY"
  6. set "arr5=7J,1T,Y6,K4,E6,84,54,87,E9,01"
  7. set "arr6=1K,HY,F1,K6,DR,4J,6R,D1,J5,RD"
  8. For /L %%i in (1,1,6) do (
  9.     set /a rn=!random!%%10+1
  10.     call:next !rn! "!arr%%i!" str
  11. )
  12. echo !str!
  13. pause&exit
  14. :next
  15. 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代码,都是些个简单的东西
  1. $a =  '12','06','86','46','12','DF','55','SE','11','CA' |Get-Random
  2. $b = 'F5','F4','DG','4S','6G','4S','65','ZG','14','65' |Get-Random
  3. $c = 'ZS','D4','FG','SZ','1G','8S','ZD','4G','56','S4' |Get-Random
  4. $d = 'GZ','SG','4S','D5','4G','FD','84','H5','6D','FY' |Get-Random
  5. $e = '7J','1T','Y6','K4','E6','84','54','87','E9','01' |Get-Random
  6. $f = '1K','HY','F1','K6','DR','4J','6R','D1','J5','RD' |Get-Random
  7. $结果 = "" + $a  + $b +  $c + $d + $e + $f
  8. Write-Host $结果
  9. #这个基本上就是,产生随机密码的脚本   
复制代码

作者: terse    时间: 2014-1-6 16:20

PS 练手
  1. $arr = @(
  2. "12,06,86,46,12,DF,55,SE,11,CA"
  3. "F5,F4,DG,4S,6G,4S,65,ZG,14,65"
  4. "ZS,D4,FG,SZ,1G,8S,ZD,4G,56,S4"
  5. "GZ,SG,4S,D5,4G,FD,84,H5,6D,FY"
  6. "7J,1T,Y6,K4,E6,84,54,87,E9,01"
  7. "1K,HY,F1,K6,DR,4J,6R,D1,J5,RD"
  8. )
  9. $str = foreach ( $a in $arr) {$a.split(",") | Get-Random}
  10. $str -join ""
复制代码





欢迎光临 批处理之家 (http://bathome.net./) Powered by Discuz! 7.2