Saved Bookmarks
| 1. |
Solve : random character between every word in set /p? |
|
Answer» hi now i want set random character between every word.. this little snippet should help: Code: [Select]@echo off setlocal enabledelayedexpansion set /p var=Enter PW: set string=%var% :length if defined var (set var=%var:~1%& set /a length+=1 & goto length) set /a length-=1 for /l %%i in (0, 1, %length%) do ( call set chr=%%string:~%%i,1%% call :random if %%i EQU !length! (set outline=!outLine!!chr!) else (set outLine=!outLine!!chr!!rnd!) ) echo %outLine% goto :eof :random set intLowNumber=0 set intHighNumber=9 set /a rnd=%random% %% (%intHighNumber% - %intLowNumber% + 1) + %intLowNumber% I limited the random number to one character but that can easily be changed within the :random routine. The %random% variable only outputs NUMBERS so if you need random alpha characters let us know (no extra charge). Quote from: Sidewinder on February 18, 2013, 08:43:17 AM The nice thing about having a snippet closet is not having to actually write scripts, just assemble them from previous masterpieces! thanks sooo much that exactly what i wanted! one more question: Quote from: foxidrive on February 18, 2013, 05:30:54 AM how can i add alpha random character? tnxAs seen on TV: Code: [Select]@echo off setlocal enabledelayedexpansion set chrTable=abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ set chrCount=52 set /p var=Enter PW: set string=%var% :length if defined var (set var=%var:~1%& set /a length+=1 & goto length) set /a length-=1 for /l %%i in (0, 1, %length%) do ( call set chr=%%string:~%%i,1%% call :random if %%i EQU !length! (set outline=!outLine!!chr!) else (set outLine=!outLine!!chr!!rnd!) ) echo %outLine% goto :eof :random set /a offset=!random! %% chrCount call set rnd=%%chrTable:~!offset!,1%% All the action takes place in the :random routine using the chrTable. The chrTable contains all the characters you want to INCLUDE for processing and the chrCount variable is the count of those characters. For example, currently the chrTable contains all the upper and lower case alpha characters and the chrCount is 52. If you want to include the digits 0-9, add them to the chrTable and increase the chrCount variable to 62. You can use any combination of characters you want, just be sure the chrCount variable is set correctly. Do not use special characters in the chrTable; many of them are used by the cmd interpreter and can and will create unexpected results. thanks |
|