Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for random.bat

(view source code of random.bat as plain text)

  1. @ECHO OFF
  2. REM Random.bat,  Version 2.00 for DOS
  3. REM Random number generator
  4. REM Written by Rob van der Woude
  5. REM http://www.robvanderwoude.com
  6. REM Inspired by Tom Lavedas' "The Simple Way"
  7. REM http://www.pressroom.com/~tglbatch/oldrandm.htm
  8. REM Strip procedure by Laurence Soucy
  9. REM http://bigfoot.com/~batfiles/
  10.  
  11. REM Recursion
  12. IF "%1"=="Loop" GOTO Loop
  13. IF "%1"=="Loop?" GOTO Loop
  14.  
  15. REM Store current time in environment variable
  16. REM (adjust "TIME" string, parameter numbers
  17. REM and ENTER.BAT file name for non-US/UK DOS)
  18. VER | TIME | DATE | FIND /I "TIME" > TEMP.BAT
  19. ECHO SET RND$=%%8>ENTER.BAT
  20. ECHO IF NOT [%%9]==[] SET RND$=%%9>>ENTER.BAT
  21. CALL TEMP.BAT
  22.  
  23. REM If decimal delimiter is "," then we're ready,
  24. REM otherwise the variable needs to be "stripped"
  25. ECHO %RND$% | FIND "." >NUL
  26. IF NOT ERRORLEVEL 1 GOTO Strip
  27. ECHO %RND$% | FIND "," >NUL
  28. IF NOT ERRORLEVEL 1 GOTO Strip
  29. ECHO %RND$% | FIND ":" >NUL
  30. IF NOT ERRORLEVEL 1 GOTO Strip
  31. ECHO %RND$% | FIND ";" >NUL
  32. IF NOT ERRORLEVEL 1 GOTO Strip
  33. ECHO %RND$% | FIND "-" >NUL
  34. IF NOT ERRORLEVEL 1 GOTO Strip
  35. ECHO %RND$% | FIND "/" >NUL
  36. IF NOT ERRORLEVEL 1 GOTO Strip
  37. SET RND=%RND$%
  38. GOTO Display
  39.  
  40. :Strip
  41. REM Strip variable and use only the part after the
  42. REM last delimiter; main routine
  43. ECHO ]|CHOICE /C:;%RND$%;]; %0 Loop >TEMP2.BAT
  44. CALL TEMP2.BAT
  45.  
  46. :Display
  47. REM Show the result
  48. ECHO Random number is: %RND%
  49.  
  50. REM Clean up the mess
  51. FOR %%A IN (TEMP TEMP2 ENTER) DO IF EXIST %%A.BAT DEL %%A.BAT
  52. SET RND$=
  53. GOTO End
  54.  
  55. :Loop
  56. REM Strip variable and use only the part after the
  57. REM last delimiter; recursively called subroutine
  58. SHIFT
  59. IF "%1"==";" GOTO Loop
  60. IF "%1"=="]" GOTO End
  61. IF "%1"=="]?]" GOTO End
  62. IF "%1"=="[" GOTO Loop
  63. IF "%1"=="." SET RND=
  64. IF "%1"=="." GOTO Loop
  65. IF "%1"==":" SET RND=
  66. IF "%1"==":" GOTO Loop
  67. SET RND=%RND%%1
  68. GOTO Loop
  69.  
  70. :End
  71.  

page last uploaded: 2017-08-21, 14:26