Randomize the hash and present to the user

There are two key elements of this section of the script, the line $displayHash.Add($order[$arrayPos], $hash.get_item($count)) and $order = Get-Random -Count 10 -InputObject (1..5) 

First we create an array called $order.  This variable creates a random listing of the numbers 1-5.
  
Next, we create a new hash table called $displayHash.  This table will display that answers that the user sees / selects from.  Like our earlier hash example, the hash is has two main components: key ($order[$arrayPos]), and a value ($hash.get_item($count)).



$order = Get-Random -Count 10 -InputObject (1..5)

# -----------------------------------------------------------------------
# Generate a hash to display on screen with randomized selections
# -----------------------------------------------------------------------
While ($count -lt 6)
    {
    $arrayPos = $count - 1
    $displayHash.Add($order[$arrayPos], $hash.get_item($count))
    $count = $count + 1
    }

$displayHash.GetEnumerator() | Sort Name
Write-Host ""

No comments:

Post a Comment