Advertisement
T3RRYT3RR0R

Batch lotto Number Generator V3.0

Jan 21st, 2020 (edited)
922
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Batch 10.39 KB | None | 0 0
  1. ::: REM Saturday lotto - Rolls in groups of 8 Games of 6 balls, out of 45 possible balls, No duplicant balls (except final 3 balls (45/6 =7.5 games)).
  2. ::: REM Will Roll any Number of Games without retaining duplicate Games. (Limited to 800 Games)
  3. ::: REM Stores rolled games to a txt file, then converts the .txt to a .doc so it can be Opened in MS Word
  4. ::: REM v 3.0 Modifications - Reduced number of subroutines down to One, Refinement of Sorting subroutine through the use of Nested For Loops.
  5. ::: REM (cont) Modified call to sort routine to use nested For /L Loops to build the strings containing games to be sorted.
  6.  @Echo Off
  7. ::: REM Define escape sequence character for color output - hexadecimal: \x1B
  8.  For /F %%a in ('echo prompt $E ^| cmd')do (Set "/E=%%a")
  9. :Re_roll_All
  10.  Setlocal EnableExtensions EnableDelayedExpansion & TITLE Saturday Lotto game roller
  11. REM Stores the Folder location of the Program into a variable - Must be done before any functions are called.
  12.  Set "ProgDir=%~dp0"
  13. REM Creates a folder to store lotto numbers in
  14.  IF NOT EXIST "%ProgDir%LottoDraws" MD "%ProgDir%LottoDraws"
  15.  Set "SaveLoc=%ProgDir%LottoDraws"
  16. REM Fullscreen mode
  17.  Mode 1000
  18. REM - Game_Number variable used to track total number of Games rolled.
  19.  Set G_N=0
  20. :Choose
  21.  CLS
  22.  ECHO %/E%[1;1H%/E%[K%/E%[36m Select the number of games to roll (%/E%[34mOnly multiples of 8 permitted%/E%[36m):%/E%[34m
  23. REM Displays Game Number Options in Multiples of 8, Highlights Games that match Multiples of 18 (Equal to Playslip Maximum Games)
  24. REM cont- Multiples of 8 beyond 320 are still Valid
  25.  Set /a L_Pos=0
  26.  FOR /L %%a IN (8,8,320) DO (
  27.   Echo/%/E%[2;!L_pos!H%/E%[1m%/E%[35m%%a%/E%[0m%/E%[34m
  28.   FOR /L %%b IN (18,18,320) DO (
  29.    IF %%b==%%a (
  30.     Echo/%/E%[2;!L_pos!H%/E%[33m%%a%/E%[34m
  31.   ))
  32.    Set /a L_Pos+=4
  33.  )
  34. REM Tests to ensure input is Numerical, returns for new input if test fails
  35.  Set "stop="
  36.  Set /P "stop="
  37.  SetLocal EnableDelayedExpansion
  38.  (Echo/!stop!|"%__AppDir__%findstr.exe" /RX "[1-9][0-9]* 0">NUL||(Echo/ %/E%[31mOnly numerical input is accepted. Values with leading 0's will be rejected. & Timeout 2 >nul & ( EndLocal & Goto :Choose)) 2>NUL)
  39. REM Tests input and Limits number of Games to 800, returns for new input if test fails
  40.  IF !stop! GTR 800 (
  41.   Echo/%/E%[31m%/E%[K Maximum %/E%[33mNumber of Games Exceeded. [%/E%[32m800%/E%[33m]
  42.   Timeout 3 >Nul
  43.   (EndLocal & Goto :Choose)
  44.  )
  45. REM Tests to ensure input is a multiple of 8, returns for new input if test fails
  46.  FOR /L %%a IN (8,8,!stop!) DO (
  47.   IF "%%a"=="!stop!" (
  48.    EndLocal & Set "stop=!stop!" & GOTO :start
  49.  ))
  50.  Echo/ %/E%[33mNumber of games is %/E%[31mnot %/E%[33ma Multiple of %/E%[32m8 & TIMEOUT 2 >nul & ( EndLocal & GOTO :Choose )
  51. :start
  52.  CLS
  53. REM Current_Ball Variable used in array for balls 1 to 48 in each set of 8 games.
  54.  Set "C_B=1"
  55. REM Function to generate the first 45 balls without Duplication
  56. :gen_1to45
  57. REM Generate a Value for the Current_Ball and stores it to the current array Index.
  58.  Set /a ball[%C_B%]=%random% %%45 +1
  59. REM Nested For Loop used to determine if Current Ball is a repeat of previous balls rolled - compares from 2nd ball onwards.
  60. REM Ball count is only incremented if there is no duplication, - enforcing a reroll upon duplication with use of Label loop
  61.  If %C_B% GTR 1 (
  62.   For /L %%a In (1,1,!C_B!) DO (
  63.    For %%b In (!C_B!) Do (
  64.     If NOT "%%a"=="%%b" (
  65.      If "!ball[%%a]!"=="!ball[%%b]!" (
  66.       ECHO %/E%[2;1H%/E%[K%/E%[31m../O%/E%[32m
  67.       GOTO :gen_1to45
  68.  )))))
  69.  ECHO %/E%[2;1H%/E%[K%/E%[32m   O\..%/E%[32m
  70.  Set Games.Rolled=0
  71.  For /L %%A in (6,6,%C_B%) Do (Set /A Games.Rolled+=1)
  72.  Set /A Games.Rolled+=G_N
  73.  Title  %Games.Rolled% Games succesfully rolled.
  74.  ECHO %/E%[1;1H%/E%[K%/E%[33mRolling Ball : [%/E%[37m!C_B!%/E%[33m]
  75.  If "!C_B!"=="45" (GOTO :gen_46to48) Else (Set /A "C_B+=1" & GOTO :gen_1to45)
  76. REM Function to Generate the Last 3 Balls, Duplication of 3 balls from games one to 7 required to round out the 8th game.
  77. :gen_46to48
  78.  ECHO %/E%[1;1H%/E%[K%/E%[33mRolling Ball : [%/E%[37m46-48%/E%[33m]
  79.  For /L %%a In (46,1,48) Do (Set /A "ball[%%a]=!random! %%45 + 1" & Echo/ %/E%[1;1H%/E%[K%/E%[33mRolling Ball : [%/E%[37m%%a%/E%[33m])
  80. REM Progressively compares balls 42 - 48 against each other for duplicants
  81.  FOR /L %%a In (42,1,48) DO (
  82.   For /L %%b In (43,1,48) Do (
  83.    If NOT "%%a"=="%%b" (
  84.     IF "!ball[%%a]!"=="!ball[%%b]!" (
  85.      Echo/ %/E%[2;1H%/E%[K%/E%[31m../O%/E%[32m
  86.      GOTO :gen_46to48
  87.     ) Else (
  88.      Echo/ %/E%[1;1H%/E%[K%/E%[33mRolling Ball : [%/E%[37m%%a%/E%[33m]
  89.      Echo/ %/E%[2;1H%/E%[K%/E%[32m   O\..%/E%[32m
  90.  ))))
  91.  Set "Games.Rolled=1"
  92.  For /L %%A in (6,6,%C_B%) Do (Set /A Games.Rolled+=1)
  93.  Set /A Games.Rolled+=G_N
  94.  Title  %Games.Rolled% Games succesfully rolled.
  95. REM Build a string containing each set of 6 balls prefixed with a call to the sort routine.
  96. REM (Call contains each set of 6 ball indices as parameters, and is enacted each time the string is built.)
  97. REM Assignment of each game to the incremented index number occurs in the sort routine.
  98. ECHO %/E%[1;1H%/E%[K%/E%[36mSorting...
  99.  Set "Call_Sort=Call :Sort"
  100.  FOR /L %%A in (1,1,48) Do (
  101.   Set "Call_Sort=!Call_Sort! ball[%%A]"
  102.   For /L %%B in (6,6,48) Do (
  103.    IF "%%B"=="%%A" (
  104.     Set /A G_N+=1
  105.     !Call_Sort!
  106.     Set "Call_Sort=Call :Sort"
  107.  )))
  108. REM Loops back to start until all games rolled
  109.  IF !G_N! LSS !stop! Goto :Start
  110. REM Uses Nested for loop to compare the value of each game against the value of each other game.
  111.  For /L %%a in (1,1,!G_N!) Do (
  112.   For /L %%b in (2,1,!G_N!) Do (
  113.    If Not "%%a"=="%%b" (
  114.     ECHO %/E%[1;1H%/E%[31m%/E%[07m%/E%[K Comparing:%/E%[32m
  115.     ECHO %/E%[2;1H%/E%[0m%/E%[K%/E%[37m Game[%/E%[33m%%a%/E%[37m] %/E%[36m!game[%%a]!%/E%[32m
  116.     ECHO %/E%[3;1H%/E%[K%/E%[35mVs.%/E%[32m
  117.     ECHO %/E%[4;1H%/E%[K%/E%[37m Game[%/E%[33m%%b%/E%[37m] %/E%[34m!game[%%b]!%/E%[32m
  118.     IF "!game[%%a]!"=="!game[%%b]!" (
  119.      cls
  120.      Echo/game[%%a] = !game[%%a]! matches game[%%b] = !game[%%b]!
  121.      Set "G_N=0"
  122.      pause
  123.      GOTO :start
  124.  ))))
  125. :finish
  126. REM Move into the lotto draw subfolder to Save file, perform renames, deletions Etc
  127.  PUSHD "%SaveLoc%"
  128. REM Places the program into a holding loop if the timestamped file already exists. Will break out of the loop when
  129. REM (cont) the Minute passes.
  130. :CheckSuffix
  131. REM Establish date and time suffix for filename
  132.  Set "suffix=%DATE%"
  133.  Set "suffix=%suffix: =%"
  134.  Set "suffix=%suffix%%TIME%"
  135.  Set "suffix=%suffix:/=%"
  136.  Set "suffix=%suffix::=%"
  137.  Set "suffix=%suffix:.=%"
  138.  Set "suffix=%suffix: =0%"
  139.  Set "suffix=%suffix:~3,12%"
  140.  IF EXIST "LottoNumbers%suffix%.doc" (
  141.   CLS
  142.   Echo/%/E%[1;1H%/E%[K%/E%[31m"LottoNumbers%suffix%.doc" %/E%[37m Already Exists
  143.   Echo/%/E%[2;1H%/E%[K%/E%[33mWaiting for File Timestamp to become Avialable...
  144.   Timeout 1 >Nul
  145.   GOTO :CheckSuffix
  146.  ) else (
  147.   cls
  148.   Echo/%/E%[1;1H%/E%[K%/E%[33m Generation Results Stored in "%SaveLoc%\LottoNumbers%suffix%.doc"
  149.  )
  150. REM Expands game Array and Displays to Screen, then Saves to file.
  151.  
  152.  FOR /L %%a IN (1,1,!G_N!) DO (
  153.   Echo/%/E%[37mGame[%/E%[33m%%a%/E%[37m] %/E%[90m:%/E%[36m !game[%%a]!
  154.   Echo/Game[%%a] : !game[%%a]!>>"%SaveLoc%\LottoNumbers%suffix%.txt"
  155.   FOR /L %%b in (18,18,!G_N!) DO (
  156. REM Insert break after every 18th game - 18 Games per Playslip
  157.    IF %%a==%%b (
  158.     Echo/
  159.     Echo/>>"%SaveLoc%\LottoNumbers%suffix%.txt"
  160.    )
  161.   )
  162.   FOR /L %%c in (54,54,!G_N!) DO (
  163. REM Insert page break after every 54th game - Align Games with page break in Word
  164.    IF %%a==%%c (
  165.     Echo/
  166.     Echo/>>"%SaveLoc%\LottoNumbers%suffix%.txt"
  167.  )))
  168. REM Change File to microsoft word extension type
  169.  REN LottoNumbers%suffix%.txt LottoNumbers%suffix%.doc
  170.  Pause
  171. :_Options
  172.  cls
  173.  Echo/%/E%[37mMenu. %/E%[33mIf not Exiting, You are returned here.%/E%[36m
  174.  CHOICE /N /C erovd /M "(E)xit (R)oll Agian (O)pen in Word (V)iew in Folder (D)elete Previous Generations"
  175.  IF %errorlevel%==5 (
  176.   Set "Del_C=0"
  177.   For %%a IN (LottoNumbers*.doc) DO (
  178.    IF NOT "%%~nxa"=="LottoNumbers%suffix%.doc" (
  179.     cls
  180.     Echo/%/E%[3;1H%/E%[K%/E%[33mConfirm:%/E%[31m
  181.     DEL /P "%%~nxa"
  182.     Set /a "Del_C+=1"
  183.    )
  184.   )
  185.   Echo/%/E%[4;1H%/E%[K%/E%[32mFiles Removed = %/E%[33m!Del_C!%/E%[35m
  186.   Timeout 3
  187.   GOTO :_Options
  188.  )
  189.  IF %errorlevel%==4 (
  190.   Echo/%/E%[1;1H%/E%[K%/E%[32mOpening %/E%[33m%SaveLoc% %/E%[32mCurrent Game is:%/E%[33m LottoNumbers%suffix%.doc%/E%[35m
  191.   Echo/%/E%[2;1H%/E%[K
  192. REM Opens the Folder containing the lotto draw in windows Explorer
  193.   explorer.exe "%SaveLoc%"
  194.   pause
  195.   GOTO :_Options
  196.  )
  197. REM Unwanted folders are created in the process of renaming and opening the file with word using the start command.
  198. REM The program needs to wait for Word to be closed before it can remove those unwanted folders.
  199.  IF %errorlevel%==3 (
  200.   cls & Color 04 & Echo/Close Microsoft Word to continue.
  201. REM Start file in Default Program
  202.   START /wait "" "%SaveLoc%\LottoNumbers%suffix%.doc"
  203.   cls & Color 03 & ECHO Cleanup In Progress...
  204.   FOR /L %%a in (1,1,50) DO (
  205.    RMDIR /Q /S "%SaveLoc%\%%a" 2>nul
  206.   )
  207.   GOTO :_Options
  208.  )
  209.  IF %errorlevel%==2 (
  210. REM Return to the Previous Folder
  211.   POPD
  212.   ENDLOCAL & GOTO :Re_roll_All
  213.  )
  214. REM *** End Script Main. Commence Functions. *** ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  215. REM command executes if choice errorlevel EQU 1
  216.  EXIT /B 0
  217. :sort
  218.  SetLocal EnableDelayedExpansion
  219. REM assign the current game index to a variable for return past the Endlocal barrier
  220.  Set "game=game[!G_N!]"
  221. REM tkn[i] Temporary indexed variables used to Sort values passed by parameter.
  222. REM tkn[i] is the value of the Ball number of the Calling Round.
  223.  Set "tkn[1]=!%1!"
  224.  Set "tkn[2]=!%2!"
  225.  Set "tkn[3]=!%3!"
  226.  Set "tkn[4]=!%4!"
  227.  Set "tkn[5]=!%5!"
  228.  Set "tkn[6]=!%6!"
  229. REM Sorts from Last ball to First, Comparing against each previous Ball and exchanging places along the way.
  230. REM (cont) On IF Condition being true, the Value of tkn[i] is swapped for the ball being compared through use of a temporary Variable.
  231.  For /L %%a In (1,1,5) Do (
  232.   Set /A S_Offset=1 + %%a
  233.   For /L %%b IN (1,1,%%a) DO (
  234.    For %%c in (!S_Offset!) DO (
  235.     IF !tkn[%%c]! LSS !tkn[%%b]! (
  236.      Set tmp=!tkn[%%c]!
  237.      Set tkn[%%c]=!tkn[%%b]!
  238.      Set tkn[%%b]=!tmp!
  239.      ECHO %/E%[2;1H%/E%[K%/E%[33m^<^<^<^<^<%/E%[32m
  240.     ) else (
  241.      ECHO %/E%[2;1H%/E%[K%/E%[32m==I==%/E%[32m
  242.  ))))
  243. REM Assign sorted balls in current set of six to current game index.
  244.  Set "tmpG=!tkn[1]!,!tkn[2]!,!tkn[3]!,!tkn[4]!,!tkn[5]!,!tkn[6]!"
  245.  (
  246.  EndLocal
  247.  Set "%game%=%tmpG%"
  248.  Exit /B
  249.  )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement