Advertisement
T3RRYT3RR0R

String Shuffler

Aug 4th, 2022 (edited)
1,233
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Batch 1.07 KB | None | 0 0
  1. @Echo off
  2.  
  3. REM example
  4. SETLOCAL
  5.     Set "String[1]=Some !@#$%%^& string"
  6.     If not "%~1"=="" Set "String[1]=%~1"
  7.     Call:Mixer String[1] String[2]
  8.     Set String
  9.     Pause
  10. ENDLOCAL & Goto:Eof
  11.  
  12. :Mixer <SourceVariable> <ReturnVariable>
  13. Setlocal DISABLEdelayedexpansion
  14.     If "%~2" == "" Exit /b 2
  15.     If "%~1" == "" Exit /b 1
  16.     For /f "tokens=1 delims==" %%G in ('Set Char[ 2^> nul') Do Set "%%G="
  17.  
  18.     For /f "UsebackQ tokens=1,2 Delims=:" %%G in (`cmd /V:On /u /c  ^"^<nul set/p "=!%~1!"^"^| find /v "" ^| findstr /n "^"`)Do (
  19.         Set "Char[%%G]=%%H"
  20.         Set "Count=%%G"
  21.     )
  22.  
  23.     Set "string="
  24.     Setlocal EnableDelayedexpansion
  25.  
  26.     %= For each in reducing array  =%   For /l %%i in (%Count% -1 1)Do (
  27.     %= Select random index to      =%       Set /A {Random_Index}=!Random! %% %%i + 1
  28.     %= expand from                 =%       For %%r in (!{Random_Index}!)Do (
  29.     %= Append Char @index 2 string =%           Set "String=!String!!Char[%%r]!"
  30.     %= Swap char at last index to  =%           Set "Char[%%r]=!Char[%%i]!"
  31.     %= selected index #            =%   )   )
  32.  
  33.  
  34. (
  35.     Endlocal & Endlocal & 2> nul Set "%~2=%String%"
  36.     Exit /B 0
  37. )
  38.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement