MoonPoint Support Logo

 

Shop Amazon Warehouse Deals - Deep Discounts on Open-box and Used ProductsAmazon Warehouse Deals



Advanced Search
July
Sun Mon Tue Wed Thu Fri Sat
         
3
           
2016
Months
Jul


Sun, Jul 03, 2016 10:55 pm

Generate random numbers on a Microsoft Windows system

If you need to produce a random number on a Microsoft Windows system, you can do so at a command line interface (CLI) or in a batch file using the %RANDOM% environment variable - see Windows Environment Variables for a list of the environment variables available on Microsoft Windows systems.

To generate random numbers at the command line, you can open a command prompt window and type echo %random%.

c:\Users\Public\Documents>echo %random%
31090

c:\Users\Public\Documents>echo %random%
16802

c:\Users\Public\Documents>echo %random%
20253

c:\Users\Public\Documents>

When you use %random%, you will get numbers between 0 and 32,767, which is 2 to the 15th power. But you can make the range of numbers smaller by using a command like the following where 0 is the lower bound for the numbers and n-1 is the upper bound of the range.

SET /a _rand=(%RANDOM%*n/32768)

[ More Info ]

[/os/windows] permanent link

Valid HTML 4.01 Transitional

Privacy Policy   Contact

Blosxom logo