DOCUMENT(); loadMacros('PGstandard.pl', 'PGML.pl', 'parserCheckboxList.pl', 'PGcourse.pl'); # have 1 or 2 incorrect answers $numberOfIncorrect = random(1,2); # randomly choose which are incorrect @whichAreIncorrect = random_subset($numberOfIncorrect, (0,1,2)); # make the array of which are CORRECT, which is so much more complicated in Perl than it is in Python @whichAreCorrect = (0,1,2); for $remove (@whichAreIncorrect) { @whichAreCorrect = grep { $_ != $remove } @whichAreCorrect; } # the correct answers @answers = (3,5,8); # make these answers incorrect by adding one to them for (@whichAreIncorrect) { $answers[$_] += 1; } $checks1 = CheckboxList( [ "\(1+2=$answers[0]\)", "\(2+3=$answers[1]\)", "\(4+4=$answers[2]\)", 'None of the above' ], @whichAreCorrect ); BEGIN_PGML Choose which equations are correct: [_]{$checks1} END_PGML ENDDOCUMENT();