echo %RANDOM% ... {0, 32767}

I knew there are environment variables for SystemRoot, UserProfile, etc, but I didn't know about the %RANDOM% variable that when used will generate a random number between 0 and 32767.
 
I remember a few years ago I needed to generate a unique name for something in a batch file and I had to use an external program to generate a random number. This can come in handy for generating temporary and/or unique file names.
 
For a complete list of Windows XP Environment variables see Command shell overview.
Published Monday, September 27, 2004 8:18 PM by puzzlehacker

Comments

# re: echo %RANDOM% ... {0, 32767}

Great tip! I'd always parsed date and time to create unique filenames, but this is much easier. I guess there's a chance of collisions, but pretty small.

Wednesday, September 29, 2004 2:59 AM by Jon Galloway

# re: echo %RANDOM% ... {0, 32767}

I'm not if you know already but there are also %TIME% and %DATE% variables. You can see the above link "Command shell overview" for a complete list of variables.

Wednesday, September 29, 2004 9:49 PM by Wes

# Shell commands

Friday, October 15, 2004 12:07 PM by TrackBack

# Shell commands

Friday, October 15, 2004 7:18 PM by TrackBack

Leave a Comment

(required) 
(required) 
(optional)
(required)