August 18th, 2012

PowerTip: Use PowerShell to Simplify Working with Random Numbers

Doctor Scripto
Scripter

Summary: Learn about using Windows PowerShell to generate random numbers.

Hey, Scripting Guy! Question How can I generate a random number?

Hey, Scripting Guy! Answer 

a. Use the Get-Random cmdlet.

b. Use the System.Random .NET Framework class, and call the next() method:

([random]5).next()

Hey, Scripting Guy! Question How can I generate a random number between the values of 1 and 10?

 Hey, Scripting Guy! Answer

a. Use the System.Random .NET Framework class, and call the next() method:

([random]5).next(“1”,”10”)

b. Use the Get-Random cmdlet:

Get-Random -Maximum 10 -Minimum 1

Author

The "Scripting Guys" is a historical title passed from scripter to scripter. The current revision has morphed into our good friend Doctor Scripto who has been with us since the very beginning.

0 comments

Discussion are closed.