T3RRYT3RR0R

Batch Lotto Generator (Array Function)

Jan 14th, 2020
580
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Batch 8.40 KB | None | 0 0
  1. ::: REM New Version at https://pastebin.com/bqVtyqPx
  2.  
  3. ::: 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)).
  4. ::: REM Will Roll any Number of Games without retaining duplicate Games. (until maximum number of possible Combinations reached)
  5. ::: REM Displays rolled games and Stores them to a text file
  6.  
  7. @echo off
  8. setlocal enabledelayedexpansion
  9. Mode 1000
  10.  
  11. ::: REM - Game_Number variable used to track total number of Games rolled.
  12.  
  13. Set G_N=0
  14.  
  15. :start
  16. cls
  17.  
  18. Set C_B=1
  19.  
  20. :gen_1to45
  21. ECHO Rolling Games...
  22.  
  23. Set /a ball[%C_B%]=%random% %%45 +1
  24.  
  25. :: REM - IF condition sends script to test function to determine if Current Ball is a repeat of Previous balls rolled - Condition checks from 2nd ball onwards.
  26. ::: Function Increments the Array (Ball Count) upon passing test
  27. ::: Ball count is only incremented if there is no duplication, - enforcing a reroll upon duplication.
  28.  
  29. If %C_B% GTR 1 (
  30. GOTO :testballs
  31. ) else (
  32. Set /a C_B+=1
  33. GOTO gen_1to45
  34. )
  35.  
  36. :gen_46to48
  37. ECHO Rolling Games...
  38.  
  39. Set /a ball[46]=%random% %%45 +1
  40. Set /a ball[47]=%random% %%45 +1
  41. Set /a ball[48]=%random% %%45 +1
  42.  
  43. Set "_CB=42"
  44.  
  45. ::: Progressively Calls a function to compare balls 42- 48 against each other for duplicants
  46.  
  47. For /L %%a in (43,1,47) DO (
  48. CALL :testfinal6 %%a !_CB!
  49. Set /a _CB+=1
  50. )
  51.  
  52. GOTO :display
  53.  
  54. :display
  55.  
  56. ECHO Sorting...
  57.  
  58. ::: Sorts Low to High and Sets Balls to Games in groups of 6, assigned to Array according to game Number.
  59.  
  60.  Set /a G_N+=1
  61. CALL :sort ball[1] !ball[1]! ball[2] !ball[2]! ball[3] !ball[3]! ball[4] !ball[4]! ball[5] !ball[5]! ball[6] !ball[6]!
  62. Set "game[!G_N!]=!ball[1]!,!ball[2]!,!ball[3]!,!ball[4]!,!ball[5]!,!ball[6]!"
  63. Set check[1]=!game[%G_N%]!
  64.  
  65. Set /a G_N+=1
  66. CALL :sort ball[7] !ball[7]! ball[8] !ball[8]! ball[9] !ball[9]! ball[10] !ball[10]! ball[11] !ball[11]! ball[12] !ball[12]!
  67. Set "game[!G_N!]=!ball[7]!,!ball[8]!,!ball[9]!,!ball[10]!,!ball[11]!,!ball[12]!"
  68. Set check[2]=!game[%G_N%]!
  69.  
  70. Set /a G_N+=1
  71. CALL :sort ball[13] !ball[13]! ball[14] !ball[14]! ball[15] !ball[15]! ball[16] !ball[16]! ball[17] !ball[17]! ball[18] !ball[18]!
  72. Set "game[!G_N!]=!ball[13]!,!ball[14]!,!ball[15]!,!ball[16]!,!ball[17]!,!ball[18]!"
  73. Set check[3]=!game[%G_N%]!
  74.  
  75. Set /a G_N+=1
  76. CALL :sort ball[19] !ball[19]! ball[20] !ball[20]! ball[21] !ball[21]! ball[22] !ball[22]! ball[23] !ball[23]! ball[24] !ball[24]!
  77. Set "game[!G_N!]=!ball[19]!,!ball[20]!,!ball[21]!,!ball[22]!,!ball[23]!,!ball[24]!"
  78. Set check[4]=!game[%G_N%]!
  79.  
  80. Set /a G_N+=1
  81. CALL :sort ball[25] !ball[25]! ball[26] !ball[26]! ball[27] !ball[27]! ball[28] !ball[28]! ball[29] !ball[29]! ball[30] !ball[30]!
  82. Set "game[!G_N!]=!ball[25]!,!ball[26]!,!ball[27]!,!ball[28]!,!ball[29]!,!ball[30]!"
  83. Set check[5]=!game[%G_N%]!
  84.  
  85. Set /a G_N+=1
  86. CALL :sort ball[31] !ball[31]! ball[32] !ball[32]! ball[33] !ball[33]! ball[34] !ball[34]! ball[35] !ball[35]! ball[36] !ball[36]!
  87. Set "game[!G_N!]=!ball[31]!,!ball[32]!,!ball[33]!,!ball[34]!,!ball[35]!,!ball[36]!"
  88. Set check[6]=!game[%G_N%]!
  89.  
  90. Set /a G_N+=1
  91. CALL :sort ball[37] !ball[37]! ball[38] !ball[38]! ball[39] !ball[39]! ball[40] !ball[40]! ball[41] !ball[41]! ball[42] !ball[42]!
  92. Set "game[!G_N!]=!ball[37]!,!ball[38]!,!ball[39]!,!ball[40]!,!ball[41]!,!ball[42]!"
  93. Set check[7]=!game[%G_N%]!
  94.  
  95. Set /a G_N+=1
  96. CALL :sort ball[43] !ball[43]! ball[44] !ball[44]! ball[45] !ball[45]! ball[46] !ball[46]! ball[47] !ball[47]! ball[48] !ball[48]!
  97. Set "game[!G_N!]=!ball[43]!,!ball[44]!,!ball[45]!,!ball[46]!,!ball[47]!,!ball[48]!"
  98. Set check[8]=!game[%G_N%]!
  99.  
  100. ::: REM Calls a function to compare all games and ensure no Games are the same.
  101.  
  102. IF !G_N! GTR 8 CALL :Game_Comp
  103.  
  104. ::: REM Removes previous Game file
  105.  
  106. IF EXIST "LottoNumbers.txt" (
  107. DEL /Q "LottoNumbers.txt"
  108. )
  109.  
  110. ::: REM Expands game Array and Displays to Screen, then Saves to file.
  111. cls
  112.  
  113. FOR /L %%a in (1,1,!G_N!) DO (
  114. ECHO Game[%%a] : !game[%%a]!
  115. ECHO Game[%%a] : !game[%%a]!>>LottoNumbers.txt
  116. )
  117.  
  118. :: TYPE LottoNumbers.txt
  119.  
  120. ::: REM Option to roll another lot of 8 games or Exit
  121.  
  122. ECHO [Roll More? Y/N:]
  123. CHOICE /T 2 /N /C:ynp /D y
  124. IF ERRORLEVEL==3 GOTO :hold
  125. IF ERRORLEVEL==2 GOTO :end
  126. IF ERRORLEVEL==1 GOTO :start
  127.  
  128. ::: REM *** End Script Main. Commence Functions.
  129.  
  130. :end
  131. exit
  132.  
  133. :hold
  134. pause >nul
  135. Goto :start
  136.  
  137. ::: Compares Balls using Negative Array offset, Ensuring No balls within a game Match
  138.  
  139. :testballs
  140.  
  141. Set offset=%C_B%
  142. Set /a offset-=1
  143.  
  144. For /L %%a in (1,1,!offset!) DO (
  145.     IF !ball[%%a]!==!ball[%C_B%]! (
  146.     ECHO ../O
  147.     GOTO gen_1to45
  148.  
  149.     ) else (
  150.     ECHO    O\..
  151.     )
  152. )
  153.  
  154. IF !C_B!==45 GOTO gen_46to48
  155.  
  156. Set /a C_B+=1
  157. GOTO gen_1to45
  158.  
  159. :testfinal6
  160.  
  161. Set start=%1
  162. Set _CB=%2
  163.  
  164. ::: Compares Balls using positive Array offset, Ensuring No balls within the game Match
  165.  
  166. For /L %%b in (!start!,1,48) DO (
  167. IF !ball[%_CB%]!==!ball[%%b]! (
  168.     ECHO ../O
  169.     GOTO gen_46to48
  170.     )
  171. )
  172.  
  173. GOTO :EOF
  174.  
  175. :Game_Comp
  176.  
  177. :: REM - "Comparison_Range" Variable offset by a number equal to number of the Games in each round from the total number of Rounds rolled.
  178. Set C_R=!G_N!
  179. Set /a C_R=!C_R!-8
  180.  
  181. :: REM - "_Games to Compare" Variable Counts down throughout the Comparison Range to display remaining number of Comparisons to be made.
  182. Set _GtC=!C_R!
  183.  
  184. FOR /L %%b IN (1,1,!C_R!) DO (
  185.     CALL SET /a _GtC-=1
  186.     CALL ECHO  [!_GtC!] remaining...
  187.     CALL :Comp_all %%b
  188. )
  189.  
  190. GOTO :EOF
  191.  
  192. :: REM - Comparison Function Uses Parameter from the above For Loop to identify previous games to compare the 8 Games from the current Round against
  193. :: REM - using the the below For Loop.
  194.  
  195. :Comp_all
  196. FOR /L %%c IN (1,1,8) DO (
  197. CALL ECHO  Comparing:
  198. CALL ECHO  Game[%%c] !check[%%c]!
  199. CALL ECHO Vs.
  200. CALL ECHO  Game[%1] !game[%1]!
  201.  
  202. IF "!check[%%c]!"=="!game[%1]!" (
  203.     cls
  204.     ECHO game[%%c] = !check[%%c]! matches game[%1] = !game[%1]!
  205.     Set /a G_N=!G_N!-8
  206.     pause
  207.     GOTO :start
  208.     )
  209. )
  210.  
  211. GOTO :EOF
  212.  
  213. ::: REM - Assigns the Parameters to values to Allow Sorting and return of Sorted Values to game Array
  214. :: REM tkn[n] is the value of the Ball number of the Calling Round.
  215. :: REM return[n] is the Variable Name the Value of the Ball is to be returned to.
  216.  
  217. :sort
  218.  
  219. set S_O=0
  220.  
  221. For %%a in (%*) DO (
  222. Set /a S_O+=1
  223. IF !S_O!==1 SET return[1]=%%a
  224. IF !S_O!==2 SET tkn[1]=%%a
  225. IF !S_O!==3 SET return[2]=%%a
  226. IF !S_O!==4 SET tkn[2]=%%a
  227. IF !S_O!==5 SET return[3]=%%a
  228. IF !S_O!==6 SET tkn[3]=%%a
  229. IF !S_O!==7 SET return[4]=%%a
  230. IF !S_O!==8 SET tkn[4]=%%a
  231. IF !S_O!==9 SET return[5]=%%a
  232. IF !S_O!==10 SET tkn[5]=%%a
  233. IF !S_O!==11 SET return[6]=%%a
  234. IF !S_O!==12 SET tkn[6]=%%a
  235. )
  236.  
  237. ::: REM - Sorts from Last ball to First, Comparing against each previous Ball and exchanging places along the way.
  238. :: On IF Condition being true, the Value of tkn[n] is exchanged with the ball being compared through use of a temporary Variable.
  239.  
  240. FOR /L %%a IN (1,1,5) DO (
  241.     CALL :Delay 2
  242.     IF !tkn[6]! LSS !tkn[%%a]! (
  243.     Set tmp=!tkn[6]!
  244.     Set tkn[6]=!tkn[%%a]!
  245.     Set tkn[%%a]=!tmp!
  246.     ECHO ^<^<^<^<^<
  247.  
  248.     ) else (
  249.     ECHO ==I==
  250.     )
  251. )
  252.  
  253. FOR /L %%a IN (1,1,4) DO (
  254.     CALL :Delay 2
  255.     IF !tkn[5]! LSS !tkn[%%a]! (
  256.     Set tmp=!tkn[5]!
  257.     Set tkn[5]=!tkn[%%a]!
  258.     Set tkn[%%a]=!tmp!
  259.     ECHO ^<^<^<^<^<
  260.  
  261.     ) else (
  262.     ECHO ==I==
  263.     )
  264. )
  265.  
  266. FOR /L %%a IN (1,1,3) DO (
  267.     CALL :Delay 2
  268.     IF !tkn[4]! LSS !tkn[%%a]! (
  269.     Set tmp=!tkn[4]!
  270.     Set tkn[4]=!tkn[%%a]!
  271.     Set tkn[%%a]=!tmp!
  272.     ECHO ^<^<^<^<^<
  273.  
  274.     ) else (
  275.     ECHO ==I==
  276.     )
  277. )
  278.  
  279. FOR /L %%a IN (1,1,2) DO (
  280.     CALL :Delay 2
  281.     IF !tkn[3]! LSS !tkn[%%a]! (
  282.     Set tmp=!tkn[3]!
  283.     Set tkn[3]=!tkn[%%a]!
  284.     Set tkn[%%a]=!tmp!
  285.     ECHO ^<^<^<^<^<
  286.  
  287.     ) else (
  288.     ECHO ==I==
  289.     )
  290. )
  291.  
  292. FOR /L %%a IN (1,1,1) DO (
  293.     CALL :Delay 2
  294.     IF !tkn[2]! LSS !tkn[%%a]! (
  295.     Set tmp=!tkn[2]!
  296.     Set tkn[2]=!tkn[%%a]!
  297.     Set tkn[%%a]=!tmp!
  298.     ECHO ^<^<^<^<^<
  299.  
  300.     ) else (
  301.     ECHO ==I==
  302.     )
  303. )
  304.  
  305. FOR /L %%a IN (1,1,6) DO (
  306.     Set !return[%%a]!=!tkn[%%a]!
  307. )
  308. GOTO :EOF
  309.  
  310. ::: REM - Used to control the refresh rate of text on screen during FOR Loops that would otherwise refresh too quickly.
  311. :Delay
  312. FOR /L %%D IN (1,1,%1) DO (
  313. CALL :IncDelay
  314. )
  315. GOTO :EOF
  316. :IncDelay
  317. GOTO :EOF
Advertisement
Add Comment
Please, Sign In to add comment