您好,登錄后才能下訂單哦!
這篇文章將為大家詳細講解有關批處理如何顯示隨機的5個數,小編覺得挺實用的,因此分享給大家做個參考,希望大家閱讀完這篇文章后可以有所收獲。
代碼如下:
@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
關于“批處理如何顯示隨機的5個數”這篇文章就分享到這里了,希望以上內容可以對大家有一定的幫助,使各位可以學到更多知識,如果覺得文章不錯,請把它分享出去讓更多的人看到。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。