Computer Hope

Microsoft => Microsoft DOS => Topic started by: wowmaniac123 on February 19, 2010, 09:36:11 PM

Title: %random%
Post 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?
Title: Re: %random%
Post by: greg on February 20, 2010, 02:24:49 AM
 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:\>
  

Title: Re: %random%
Post by: Sidewinder on February 20, 2010, 02:51:41 AM
Quote
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. 

Code: [Select]
@echo off
set /a rnd=%random% %% 50 + 1
echo Random number between 1 and 50 is %rnd%

Good luck.  8)
Title: Re: %random%
Post by: greg on February 20, 2010, 07:52:42 AM
   Set #1:
 13, 1, 19, 3, 39
Title: Re: %random%
Post by: Salmon Trout on February 20, 2010, 07:56:50 AM
so, greg, how does that answer the OP's question?
Title: Re: %random%
Post by: greg on February 20, 2010, 08:08:03 AM
C:\>type rand.bat
Code: [Select]
@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:\>
Title: Re: %random%
Post by: greg on February 20, 2010, 10:57:17 AM
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
Title: Re: %random%
Post by: Carbon Dudeoxide on February 24, 2010, 07:15:38 PM
Not sure what you're on about, Greg....but Sidewinder's got it.
Title: Re: %random%
Post by: tommyroyall on February 24, 2010, 07:36:06 PM
Coolness 8). I was just about to ask this question   :(