Saved Bookmarks
| 1. |
Solve : Random # of lines in a large text file? |
|
Answer» I'm not sure I follow what that code means... Does that code create a percent of what is entered into %var%? no it makes "15%" of streets in file where you have them all, so you dont have to change code like sidewinder SAYS but using my method is not exact to real 15% found the problem: Code: [Select] set /a max=%num%/100*15 change to this: Code: [Select] set /a max=%num%*15/100then will be exact 15% Quote really only want to use between 10 and 25 streets you mean this ? Code: [Select]:LOOP set /p var=Enter how many streets you need: if %var% lss 10 goto LOOP if %var% gtr 25 goto LOOP hope that helps Thx for all the help, I appreciate it. Heres my final code to see what I'm doing. if anyone wants to test it just create a "STREETS.txt" file and put some lines in it for the code to call on. Code: [Select] TITLE Street Test Generator @echo off color f0 cls ECHO ============================================= ECHO Americus Fire and Emergency Services ECHO ============================================= ECHO ... ...... ...... ... ECHO MMM MMMMMM. MMMMMM MMI MM ECHO M. M. MM MM MM, ... ECHO M M. MMMMMM MMMMMM. MMMM . ECHO .MMMMMM. MM MM MO MM ECHO MM MN M. MM M. MMMMMM. MM .NMMMM MM. ECHO .. . .. . . . . . ECHO ============================================= ECHO Street Test Generator 1.0 ECHO ============================================= IF EXIST street_test.txt. (del street_test.txt.) set idx=0 for /f "tokens=* delims=" %%v in (STREETS.txt) do ( call set /a idx=%%idx%%+1 call set array.%%idx%%=%%v ) ECHO. Echo ==================================================== ECHO. :again set /p var=HELLO %username% !! Enter how many streets you need (max 40): IF %var% GTR 40 GOTO again set cnt=0 ECHO. ECHO ==================================================== ECHO. :loop call set /a cnt=%%cnt%%+1 set /a rnd=%RANDOM% %% %idx% + 1 call echo %%array.%rnd%%%>>street_test.txt call echo %%array.%rnd%%% if %cnt% LSS %var% goto loop ECHO. ECHO ==================================================== ECHO. Echo street_test.txt with %var% streets has been created. ECHO. ECHO ==================================================== ECHO. ECHO. pause |
|