1

%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.
Cœur
  • 37,241
  • 25
  • 195
  • 267
RBC
  • 39
  • 1
  • 1
  • 4
  • Your first code creates random numbers between 0 and 99, there is no incrementing – jeb Feb 28 '14 at 23:34
  • 1
    Please show us the real code you are using. What you've posted, other than generating and displaying random numbers 0..99, not 1..100 works perfectly. – Magoo Mar 01 '14 at 01:54
  • the first code runs fine on my computer, but from 0 to 99 – phuclv Mar 01 '14 at 02:00
  • Possible duplicate of [How to use random in BATCH script?](https://stackoverflow.com/questions/5777400/how-to-use-random-in-batch-script) – phuclv May 08 '18 at 16:39

3 Answers3

2
SET /A RAND=%RANDOM%%%100+1

this may work.

Endoro
  • 37,015
  • 8
  • 50
  • 63
1

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
phillipbv
  • 51
  • 6
-1

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  
man
  • 423
  • 1
  • 6
  • 11
hars
  • 1
  • 2
  • 1
    Since `%Random%` generates numbers between 0 and 32768 your approach is very ineffective and doesn't answer the question –  Dec 31 '16 at 13:26