[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖

[文本处理] 16种颜色值 让它们随机而不冲突 大神能来精减优化一下吗(已解决)

本帖最后由 smss 于 2019-7-5 07:12 编辑
  1. @echo off&SetLocal EnableDelayedExpansion
  2. set Str=0123456789abcdef
  3. for /l %%a in (1 1 2) do (set /a n = !random! %% 16
  4. for %%n in (!n!) do set Out=!Str:~%%n,1!)
  5. for /f "tokens=1* delims=%Out%" %%a in ("%Str%") do (set "Sta=%%a%%b")
  6. for /l %%a in (1 1 2) do (set /a n = !random! %% 15
  7. for %%n in (!n!) do set Oua=!Sta:~%%n,1!)
  8. for /f "tokens=1* delims=%Oua%" %%a in ("%Sta%") do (set "Stb=%%a%%b")
  9. for /l %%a in (1 1 2) do (set /a n = !random! %% 14
  10. for %%n in (!n!) do set Oub=!Stb:~%%n,1!)
  11. for /f "tokens=1* delims=%Oub%" %%a in ("%Stb%") do (set "Stc=%%a%%b")
  12. for /l %%a in (1 1 2) do (set /a n = !random! %% 13
  13. for %%n in (!n!) do set Ouc=!Stc:~%%n,1!)
  14. for /f "tokens=1* delims=%Ouc%" %%a in ("%Stc%") do (set "Std=%%a%%b")
  15. for /l %%a in (1 1 2) do (set /a n = !random! %% 12
  16. for %%n in (!n!) do set Oud=!Std:~%%n,1!)
  17. for /f "tokens=1* delims=%Ouf%" %%a in ("%Std%") do (set "Ste=%%a%%b")
  18. for /l %%a in (1 1 2) do (set /a n = !random! %% 11
  19. for %%n in (!n!) do set Oue=!Ste:~%%n,1!)
  20. for /f "tokens=1* delims=%Oue%" %%a in ("%Ste%") do (set "Stf=%%a%%b")
  21. for /l %%a in (1 1 2) do (set /a n = !random! %% 10
  22. for %%n in (!n!) do set Ouf=!Stf:~%%n,1!)
  23. for /f "tokens=1* delims=%Ouf%" %%a in ("%Stf%") do (set "Stg=%%a%%b")
  24. for /l %%a in (1 1 2) do (set /a n = !random! %% 9
  25. for %%n in (!n!) do set Oug=!Stg:~%%n,1!)
  26. for /f "tokens=1* delims=%Oug%" %%a in ("%Stg%") do (set "Sth=%%a%%b")
  27. for /l %%a in (1 1 2) do (set /a n = !random! %% 8
  28. for %%n in (!n!) do set Ouh=!Sth:~%%n,1!)
  29. for /f "tokens=1* delims=%Ouh%" %%a in ("%Sth%") do (set "Sti=%%a%%b")
  30. for /l %%a in (1 1 2) do (set /a n = !random! %% 7
  31. for %%n in (!n!) do set Oui=!Sti:~%%n,1!)
  32. for /f "tokens=1* delims=%Oui%" %%a in ("%Sti%") do (set "Stj=%%a%%b")
  33. for /l %%a in (1 1 2) do (set /a n = !random! %% 6
  34. for %%n in (!n!) do set Ouj=!Stj:~%%n,1!)
  35. for /f "tokens=1* delims=%Ouj%" %%a in ("%Stj%") do (set "Stk=%%a%%b")
  36. for /l %%a in (1 1 2) do (set /a n = !random! %% 5
  37. for %%n in (!n!) do set Ouk=!Stk:~%%n,1!)
  38. for /f "tokens=1* delims=%Ouk%" %%a in ("%Stk%") do (set "Stl=%%a%%b")
  39. for /l %%a in (1 1 2) do (set /a n = !random! %% 4
  40. for %%n in (!n!) do set Oul=!Stl:~%%n,1!)
  41. for /f "tokens=1* delims=%Oul%" %%a in ("%Stl%") do (set "Stm=%%a%%b")
  42. for /l %%a in (1 1 2) do (set /a n = !random! %% 3
  43. for %%n in (!n!) do set Oum=!Stm:~%%n,1!)
  44. for /f "tokens=1* delims=%Oum%" %%a in ("%Stm%") do (set "Stn=%%a%%b")
  45. for /l %%a in (1 1 2) do (set /a n = !random! %% 2
  46. for %%n in (!n!) do set Oun=!Stn:~%%n,1!)
  47. for /f "tokens=1* delims=%Oun%" %%a in ("%Stn%") do (set "Sto=%%a%%b")
  48. for /l %%a in (1 1 2) do (set /a n = !random! %% 1
  49. for %%n in (!n!) do set Ouo=!Sto:~%%n,1!)
  50. echo %Out%
  51. echo %Oua%
  52. echo %Oub%
  53. echo %Ouc%
  54. echo %Oud%
  55. echo %Oue%
  56. echo %Ouf%
  57. echo %Oug%
  58. echo %Ouh%
  59. echo %Oui%
  60. echo %Ouj%
  61. echo %Ouk%
  62. echo %Oul%
  63. echo %Oum%
  64. echo %Oun%
  65. echo %Ouo%
  66. color !Out!!Oua!
  67. Tools\ctext {!Out!!Oua!} 1.截屏到桌面{\n}
  68. Tools\ctext {!Out!!Oub!} 1.截屏到桌面{\n}
  69. Tools\ctext {!Out!!Ouc!} 1.截屏到桌面{\n}
  70. Tools\ctext {!Out!!Oud!} 1.截屏到桌面{\n}
  71. Tools\ctext {!Out!!Oue!} 1.截屏到桌面{\n}
  72. Tools\ctext {!Out!!Ouf!} 1.截屏到桌面{\n}
  73. Tools\ctext {!Out!!Oug!} 1.截屏到桌面{\n}
  74. Tools\ctext {!Out!!Ouh!} 1.截屏到桌面{\n}
  75. Tools\ctext {!Out!!Oui!} 1.截屏到桌面{\n}
  76. Tools\ctext {!Out!!Ouj!} 1.截屏到桌面{\n}
  77. Tools\ctext {!Out!!Ouk!} 1.截屏到桌面{\n}
  78. Tools\ctext {!Out!!Oul!} 1.截屏到桌面{\n}
  79. Tools\ctext {!Out!!Oum!} 1.截屏到桌面{\n}
  80. Tools\ctext {!Out!!Oun!} 1.截屏到桌面{\n}
  81. Tools\ctext {!Out!!Ouo!} 1.截屏到桌面{\n}
  82. pause
复制代码
我写的不够好 背景为一种随机颜色值 前景文字为16-1后的15种随机颜色值 但是会每用一次便会随机一次
前景文字颜色用第三方工具 ctext 表达式{04}  0是背景 4是文字

随便玩一下:结果值自己套用,看是不是你要的。
  1. @Echo Off  & cd /d "%~dp0"
  2. SetLocal EnableDelayedExpansion
  3. set "Color=0123456789ABCDEF"
  4. set /a n=%random% %% 16
  5. set "BackColor=!Color:~%n%,1!"
  6. for /f "tokens=1,2 delims=%BackColor%" %%a in ("%Color%") do set "Color=%%a%%b"
  7. set/a m=15
  8. :LOOP
  9. set/a n=%random% %% %m%
  10. set "ColTmp=!Color:~%n%,1!"
  11. for /f "tokens=1,2 delims=%ColTmp%" %%a in ("%Color%") do set "Color=%%a%%b"
  12. set "_COL%m%=%BackColor%%ColTmp%"
  13. if %m% geq 2 (set/a m-=1 &goto LOOP)
  14. set _COL
  15. Pause
复制代码
----------PS---------------
  1. $颜色字符 ='0123456789ABCDEF';
  2. $背景色 =Get-Random -input ([Char[]]$颜色字符);
  3. $颜色字符 =$颜色字符 -replace $背景色;
  4. $颜色 = While ( ([Char[]]$颜色字符).Count -gt 0 ) {
  5. $前景色 =Get-Random -input ([Char[]]$颜色字符);
  6. [string]::Concat($背景色,$前景色);
  7. $颜色字符 =$颜色字符 -replace $前景色;
  8. }
  9. $颜色;
  10. cmd /c Pause
复制代码
1

评分人数

TOP

python代码,只是生成随机颜色,未考虑其它。
  1. import random
  2. s="0123456789abcdef"
  3. fg=random.sample(s,15)        #先随机的不重复的 15个前景
  4. bg=(set(s)-set(fg)).pop()     # 余下的一个作背景
  5. res=["{}{}".format(bg,i) for i in fg]
  6. print(res)
复制代码
随机结果:
  1. ['5b', '56', '5f', '5d', '54', '5a', '53', '5c', '51', '50', '58', '57', '5e', '59', '52']
复制代码

TOP

返回列表