既然rand是伪随机数,%random%当然也是伪随机数。- @echo off
- setlocal enabledelayedexpansion
- set /a x = !random!
- echo !x!
- echo;
- call :time t
- for /l %%i in (%t%, -1, 0) do (
- set /a y = ((%%i * 214013 + 2531011^) ^>^> 16^) ^& 0x7fff
- if !y! equ !x! (
- echo %%i
- call :srand %%i
- call :rand z
- echo !z!
- echo;
- for /l %%j in (1, 1, 10) do (
- call :rand z
- echo !z! !random!
- )
- )
- echo;
- pause & exit
- )
-
- :time
- setlocal
- for /f %%x in ('wmic path win32_utctime get /format:list ^| findstr .') do set %%x
- set /a year = year - 1900, t = (year - 70) * 365 + ((year - 1) ^>^> 2) - 17, leap = year ^& 3
- for /f "tokens=%month%" %%i in ("-1 30 58 89 119 150 180 211 242 272 303 333 364") do set /a t += %%i
- if %leap% equ 0 if %month% gtr 1 set /a t += 1
- set /a t += day, t *= 24, t += hour, t *= 60, t += minute, t *= 60, t += second
- endlocal & set %1=%t%
- goto :eof
-
- :srand
- set /a _holdrand = %1
- goto :eof
-
- :rand
- set /a _holdrand = _holdrand * 214013 + 2531011
- set /a %1 = (_holdrand ^>^> 16) ^& 0x7fff
- goto :eof
复制代码
|