We can use a simple PowerShell command on Windows 11 or 10 to create random numbers. You can use this technique for certain real use cases, as mentioned at the end of this article. In this guide, let’s see a few examples to generate random numbers from PowerShell.
The Get-Random is the main command to output the numbers with few conditions.
Case 1: Get Random Number without any conditions
Entering only Get-Random cmdlet will output a random number in Powershell. Since we don’t give any range, the number could be anything between 0 to Int32.MaxValue (0x7FFFFFFF, 2,147,483,647).
Case 2: Get a Random Number in the range
We can restrict the number output by providing the maximum or minimum and maximum parameters. Here are a few examples.
Get-Random -Maximum 1000
In this, we haven’t input the minimum number so that it can give a random number from 0 to 1000.
Get-Random –Minimum 500 -Maximum 1000
Since we defined the minimum number, the random output number is between 500 to 1000
Where can we use these PowerShell Random Numbers?
It depends on your conditions and creativity.
We can use these numbers for specific reasons. For example, to create a PIN for Windows login or smartphone. Instead of giving our regular number patterns, this Powershell command can provide a good random number.
Let’s assume we need to create a PIN for iPhone with six digits. Here could be the PowerShell command to generate a random PIN number with 6 characters.
Get-Random –Minimum 000000 -Maximum 999999
Also, in another case, if you want to select the lucky winner from a specific number range, you can use this method to pick a random winner by the number.
Read Also: How to change date format in Windows 11 to mm/dd/yyyy
So, that was the quick and straightforward way to generate random numbers and PINs from PowerShell on Windows 10/11 or any Operating system that supports PowerShell.