Batch a random number within a range

Author Johnny Josefsson on August 17, 2012 | Print | Bookmark
%RANDOM% generates a random number between 0 - 62k (32 bit maximum int value)
% 0 tells it to stray within the 0 - 200 range
+10 tells it to start at 10

----[CODE]----
REM generate a random number within in the range of 10-200
REM
SET /A RAND=%RANDOM% % 0 +10

ECHO %RAND%
----[CODE]----


You could also just tell it how man digits to show with this:


----[CODE]----
%RANDOM:~-2%
----[CODE]----


That tells it to RANDOM a number with maximum of two digits, 0-99	
	
	

Was this article helpful?

Yes No

Category: Scripting, Batch / bat / cmd

Last updated on September 8, 2012 with 1131 views