How to generate a random number between 1 and 100

2019-09-19 08:39发布

%random% seems to go in order.

@ECHO OFF
SET /A RAND=%RANDOM% %%100
ECHO %RAND%
ECHO.

If you keep running this it increments until it reaches 100 and then the number start over. If it were random it would jump around.

@ECHO OFF
SET /A RAND=%RANDOM%
ECHO %RAND%
ECHO.

3条回答
狗以群分
2楼-- · 2019-09-19 08:55

If I understoof the question right, here's what you're looking for.

echo off
title Number from 1 to 100.
color 0a
cls

:loop
cls
set /a rand=%random% %%101
echo %rand%
pause >nul
goto loop
查看更多
够拽才男人
3楼-- · 2019-09-19 09:04
SET /A RAND=%RANDOM%%%100+1

this may work.

查看更多
时光不老,我们不散
4楼-- · 2019-09-19 09:05

hey if the problem still persists
use this code
this generates a number between a and b
tweak it to your needs

@echo off       
color 02  
echo enter value of A  
set  /p a=  
echo.   
echo  enter value of B  
set /p b=   
:main  
set no=%random%  
if  %no% GEQ %a% goto sub  
if not %no% GEQ %a% goto  main  
:sub  
if %no% LEQ  %b% goto end  
if not %no% LEQ  %b% goto  main  
:end  
echo %no%   
goto main  
查看更多
登录 后发表回答