欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

显示随机的5个数

程序员文章站 2022-04-29 17:16:07
复制代码 代码如下:@echo off :: 求1-100范围内随机的不同5个数值 :: 生成0-99之间的随机数列 r1 :: :: :: @echo off setlo...
复制代码 代码如下:

@echo off
:: 求1-100范围内随机的不同5个数值
:: 生成0-99之间的随机数列 r1
::
::
::
@echo off
setlocal enabledelayedexpansion
:: 初始化顺序数列
for /l %%i in (0,1,99) do (
set rnum%%i=%%i
)
:: 对数列进行随机交换
for /l %%i in (0,1,99) do (
set /a rnd=!random! %% 100
call set tmp=%%rnum!rnd!%%
set rnum!rnd!=!rnum%%i!
set rnum%%i=!tmp!
)
set rnum
pause
goto :eof

@echo off
:: code by jm 2006-1-5 cmd@xp
:begin
cls
set times=0
set count=0
:loop
set /a num=%random%%%99+1
if not defined num%num% (
set num%num%=%num%
set /a count+=1
call echo %%num%%
)
set /a times+=1
if %times% equ 20 (
for /l %%i in (1,1,99) do set num%%i=
set times=0
)
if %count% lss 5 goto loop
pause>nul
goto begin
@echo off
:: code by jm 2007-1-6 cmd@xp
:: 因为用到了 echo|find 的结构,速度比较慢
::
:begin
cls
set count=0
:loop
set /a num=%random%%%100+1
echo %str%|find " %num% ">nul&&goto loop
call set str=%%str%% %num%
set /a count+=1
if %count% lss 5 goto loop
echo %str%
set str=
pause
goto begin

@echo off&setlocal enabledelayedexpansion
::
::
for /l %%a in (1;1;5) do (
set/a b=!random!%%99+1
call :pp !b!
)
goto :eof
:pp
if not defined %1 (set %1=a) else goto loop
echo %1
goto :eof
:loop
set/a b=!random!%%99+1
call :pp !b!

@echo off
::
::
set max=100
set n=5
:start
cls
echo %time%
set num=
set tmp$=
:loop
set /a randomloop=(%random%+%random%+%random%)/3%%%max%+1
for %%n in (%tmp$%) do if "%randomloop%" == "%%n" goto loop
call set tmp$=%%tmp$%% %randomloop%
set /a num+=1
set random_%num%=%randomloop%
if %num% lss %n% goto loop
echo %tmp$%
echo %time%
pause
goto start
exit

@echo off
::
::
:start
cls
set num=
set tmp$=
:loop
set /a randomloop=%random%%%99+1
for %%n in (%tmp$%) do if "%randomloop%" == "%%n" goto loop
call set tmp$=%%tmp$%% %randomloop%
set /a num+=1
set random_%num%=%randomloop%
if %num% lss 5 goto loop
for /l %%n in (1,1,%num%) do call set /p= %%random_%%n%%<nul
echo.
pause
goto start
exit