Computer Hope
Microsoft => Microsoft DOS => Topic started by: wowmaniac123 on February 19, 2010, 09:36:11 PM
-
Im trying to create a batch program that will tell me a random thing everyday. I am wondering if I can set parameters on the random function. Just Percents Random seems to give me 6 digit numbers. Can I make %random% give me only a number between 1 and 50 or something like that?
-
http://www.randomizer.org/form.htm
Research Randomizer Results
1 Set of 5 Unique Numbers Per Set
Range: From 1 to 50 -- Unsorted
Job Status:
Set #1:
13, 1, 19, 3, 39
------------------------------------------
Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.
C:\>echo %random%
1646
C:\>echo %random%
20204
C:\>echo %random%
15365
C:\>echo %random%
18866
C:\>echo %random%
26543
C:\>
-
C:\>echo %random%
1646
C:\>echo %random%
20204
C:\>echo %random%
15365
C:\>echo %random%
18866
C:\>echo %random%
26543
This is either the new math or just plain fuzzy math, but none of the results appear to be between 1 and 50.
@echo off
set /a rnd=%random% %% 50 + 1
echo Random number between 1 and 50 is %rnd%
Good luck. 8)
-
Set #1:
13, 1, 19, 3, 39
-
so, greg, how does that answer the OP's question?
-
C:\>type rand.bat
@echo off
set /a rnd=%random% %% 50 + 1
echo Random number between 1 and 50 is %rnd%
Output:
C:\>rand.bat
Random number between 1 and 50 is 39
C:\>rand.bat
Random number between 1 and 50 is 22
C:\>rand.bat
Random number between 1 and 50 is 39
C:\>rand.bat
Random number between 1 and 50 is 28
C:\>rand.bat
Random number between 1 and 50 is 7
C:\>
-
Can I make %random% give me only a number between 1 and 50 or something like that?
Wowmaniac123,
You may ignore many posters who pretend they are Computer Hope Staff Moderators. They should contact you by email when they are off Topic.
I believe Sidewinder ( Post #2 this thread ) demonstrated the correct way to use %random%, the random number generator, for numbers less that 50.
Good luck with your project
-
Not sure what you're on about, Greg....but Sidewinder's got it.
-
Coolness 8). I was just about to ask this question :(