Generate a hash of the correct term (answer) and 4 other false answers

Earlier, we randomly picked a question from our imported list.  The randomly picked question was $pickQuestionNum.

Next a hash table is created that holds the correct answer and 4 additional incorrect answers.  The first entry in the hash table is the correct answer.  $hash.add(1,$tester.Item($pickQuestionNum).item)

The hash table is $hash.  .add will put an entry into the table.  (1, signals that we want to work on the first row of the table (this is called a key).  $tester.Item($pickQuestionNum).item) is the value of key 1.  $tester is the data we imported from our .csv file and .Item($pickQuestionNum).item selects the random term / question we picked earlier.

Next we have a loop that runs 4 times:  for ($i=1; $i -le 4; $i++).  We randomly select 4 potential responses and then we also add those to the hash table.

# -----------------------------------------------------------------------
# Generate a hash of answer (position 1) and other random options (2-5)
# -----------------------------------------------------------------------
$hash.add(1,$tester.Item($pickQuestionNum).item)
for ($i=1; $i -le 4; $i++)
    {
    $count = $count + 1
    $randomItem = Get-Random -minimum 0 -maximum $defcount
    $hash.add($count,$tester.Item($randomItem).item)
    }

No comments:

Post a Comment