本帖最后由 huyou96 于 2016-10-26 15:39 编辑
回复 4# ads350668398
TestRandom.bat- @echo off
- rem 操作系统自带的动态环境变量(dynamic environment variables)之%Random%会随机生成0至32767的随机数
- rem 从该随机产生的结果中获取从0到9的随机数并列印产生该随机数的时间
- rem 一旦有符合条件结果产生就终结退出批处理脚本
- rem 如果想生成正好等于1的随机数并获取生成1的时间,请使用下面“::”所注释的那条语句
- rem 不过可能无法在短时间内产生想要的结果……也许跑上个把钟头也不会生成正好等于1的随机数呢……
- :Beginning
- echo Please waiting...
- for /f "delims=" %%r in ('echo %Random%') do set currandom=%%r
- for /f "delims=" %%t in ('echo %Time%') do set curtime=%%t
- echo %currandom%
- :: if %currandom% equ 1 echo Get %currandom% at %curtime% && goto End
- if %currandom% leq 9 echo Get %currandom% at %curtime% && goto End
- if %ErrorLevel% equ 0 goto Beginning
- :End
复制代码 得到4的结果:
Please waiting...
15711
Please waiting...
26034
Please waiting...
8819
Please waiting...
15731
Please waiting...
24923
Please waiting...
7385
Please waiting...
8941
Please waiting...
7286
Please waiting...
11328
Please waiting...
26791
Please waiting...
3409
Please waiting...
31267
Please waiting...
10729
Please waiting...
25560
Please waiting...
5750
Please waiting...
26825
Please waiting...
20732
Please waiting...
25038
Please waiting...
24140
Please waiting...
31330
Please waiting...
22044
Please waiting...
17643
Please waiting...
31927
Please waiting...
27158
Please waiting...
16224
Please waiting...
5183
Please waiting...
20638
Please waiting...
32513
Please waiting...
19460
Please waiting...
5219
Please waiting...
17727
Please waiting...
3126
Please waiting...
1119
Please waiting...
26532
Please waiting...
453
Please waiting...
12804
Please waiting...
1557
Please waiting...
31076
Please waiting...
14108
Please waiting...
17528
Please waiting...
24718
Please waiting...
14526
Please waiting...
4
Get 4 at 14:27:29.51
(在下午14点27分29秒51这个时间得到了4这个随机数) |