PowerShell: Assigning Two Unique Random Numbers

If you need to get two random numbers from a given numeric range, and you want to make sure they cannot be the same, simply tell Get-Random to pick two numbers, and assign them to two different variables at the same time:

$foreground, $background = Get-Random -InputObject (0..15) -Count 2

In our example, you would draw a random foreground and background color while ensuring that foreground and background color can never be the same:

Write-Host -fore $foreground -back $background 'This is random coloring'

One Response to “PowerShell: Assigning Two Unique Random Numbers”

  1. cheap authentic jordans November 19, 2012 at 11:14 am #

    Enjoyed every bit of your post.Thanks Again

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

revia in alcoholism